[PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt

Paolo Abeni posted 6 patches 1 year, 3 months ago
There is a newer version of this series
[PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Paolo Abeni 1 year, 3 months ago
Some user-space applications want to monitor the subflows utilization.

Dumping the per subflow tcp_info is not enough, as the PM could close
and re-create the subflows under-the-hood, fooling the accounting.
Even checking the src/dst addresses used by each subflow could not
be enough, because new subflows could re-use the same address/port of
the just closed one.

This patch introduces a new socket option, allow dumping all the relevant
information all-at-once (everything, everywhere...), in a consistent manner.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
v2 -> v3:
 - added missing changelog (oops)
---
 include/uapi/linux/mptcp.h | 16 ++++++++
 net/mptcp/sockopt.c        | 75 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)

diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h
index 32af2d278cb4..f4f42d88e58b 100644
--- a/include/uapi/linux/mptcp.h
+++ b/include/uapi/linux/mptcp.h
@@ -12,6 +12,7 @@
 #include <linux/in.h>		/* for sockaddr_in			*/
 #include <linux/in6.h>		/* for sockaddr_in6			*/
 #include <linux/socket.h>	/* for sockaddr_storage and sa_family	*/
+#include <linux/tcp.h>		/* for tcp_info				*/
 
 #define MPTCP_SUBFLOW_FLAG_MCAP_REM		_BITUL(0)
 #define MPTCP_SUBFLOW_FLAG_MCAP_LOC		_BITUL(1)
@@ -244,9 +245,24 @@ struct mptcp_subflow_addrs {
 	};
 };
 
+struct mptcp_subflow_info {
+	__u32				id;
+	struct mptcp_subflow_addrs	addrs;
+};
+
+/* struct subflow_info is not supposed nor allowed to grow in
+ * future versions.
+ * If need will arise, a new socket option should be added.
+ */
+struct mptcp_subflow_full_info {
+	struct mptcp_subflow_info	subflow_info;
+	struct tcp_info			tcp_info;
+};
+
 /* MPTCP socket options */
 #define MPTCP_INFO		1
 #define MPTCP_TCPINFO		2
 #define MPTCP_SUBFLOW_ADDRS	3
+#define MPTCP_FULL_INFO		4
 
 #endif /* _UAPI_MPTCP_H */
diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index d4258869ac48..b4d04d5dc1f7 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -1146,6 +1146,79 @@ static int mptcp_getsockopt_subflow_addrs(struct mptcp_sock *msk, char __user *o
 	return 0;
 }
 
+static int mptcp_getsockopt_full_info(struct mptcp_sock *msk, char __user *optval,
+				      int __user *optlen)
+{
+	struct mptcp_subflow_context *subflow;
+	struct sock *sk = (struct sock *)msk;
+	unsigned int sfcount = 0, copied = 0;
+	int mptcp_info_len, len, size_user;
+	struct mptcp_subflow_data sfd;
+	char __user *infoptr;
+
+	len = mptcp_get_subflow_data(&sfd, optval, optlen);
+	if (len < 0)
+		return len;
+
+	/* don't bother filling the mptcp info if there is not enough
+	 * user-space-provided storage
+	 */
+	infoptr = optval + sfd.size_subflow_data;
+	if (len > sizeof(struct mptcp_subflow_data)) {
+		struct mptcp_info mptcp_info;
+
+		memset(&mptcp_info, 0, sizeof(mptcp_info));
+		mptcp_info_len = min_t(unsigned int, len, sizeof(struct mptcp_info));
+
+		mptcp_diag_fill_info(msk, &mptcp_info);
+
+		if (copy_to_user(infoptr, &mptcp_info, mptcp_info_len))
+			return -EFAULT;
+
+		len -= mptcp_info_len;
+		copied += mptcp_info_len;
+		infoptr += mptcp_info_len;
+	}
+
+	sfd.size_kernel = sizeof(struct mptcp_subflow_full_info);
+	sfd.size_user = min_t(unsigned int, sfd.size_user,
+			      sizeof(struct mptcp_subflow_full_info));
+	lock_sock(sk);
+
+	mptcp_for_each_subflow(msk, subflow) {
+		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+
+		++sfcount;
+		if (len >= size_user) {
+			struct mptcp_subflow_full_info sinfo;
+
+			memset(&sinfo, 0, sizeof(sinfo));
+			sinfo.subflow_info.id = subflow->subflow_id;
+			mptcp_get_sub_addrs(ssk, &sinfo.subflow_info.addrs);
+
+			/* don't bother filling the tcp info if the storage is too small */
+			if (sfd.size_user > sizeof(struct mptcp_subflow_info))
+				tcp_get_info(ssk, &sinfo.tcp_info);
+
+			if (copy_to_user(infoptr, &sinfo, sfd.size_user)) {
+				release_sock(sk);
+				return -EFAULT;
+			}
+
+			infoptr += sfd.size_user;
+			copied += sfd.size_user;
+			len -= sfd.size_user;
+		}
+	}
+	release_sock(sk);
+
+	sfd.num_subflows = sfcount;
+	if (mptcp_put_subflow_data(&sfd, optval, copied, optlen))
+		return -EFAULT;
+
+	return 0;
+}
+
 static int mptcp_put_int_option(struct mptcp_sock *msk, char __user *optval,
 				int __user *optlen, int val)
 {
@@ -1219,6 +1292,8 @@ static int mptcp_getsockopt_sol_mptcp(struct mptcp_sock *msk, int optname,
 	switch (optname) {
 	case MPTCP_INFO:
 		return mptcp_getsockopt_info(msk, optval, optlen);
+	case MPTCP_FULL_INFO:
+		return mptcp_getsockopt_full_info(msk, optval, optlen);
 	case MPTCP_TCPINFO:
 		return mptcp_getsockopt_tcpinfo(msk, optval, optlen);
 	case MPTCP_SUBFLOW_ADDRS:
-- 
2.40.1
Re: [PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Florian Westphal 1 year, 3 months ago
Paolo Abeni <pabeni@redhat.com> wrote:
> Some user-space applications want to monitor the subflows utilization.
> 
> Dumping the per subflow tcp_info is not enough, as the PM could close
> and re-create the subflows under-the-hood, fooling the accounting.
> Even checking the src/dst addresses used by each subflow could not
> be enough, because new subflows could re-use the same address/port of
> the just closed one.
> 
> This patch introduces a new socket option, allow dumping all the relevant
> information all-at-once (everything, everywhere...), in a consistent manner.
> 
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> ---
> v2 -> v3:
>  - added missing changelog (oops)
> ---
>  include/uapi/linux/mptcp.h | 16 ++++++++
>  net/mptcp/sockopt.c        | 75 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 91 insertions(+)
> 
> diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h
> index 32af2d278cb4..f4f42d88e58b 100644
> --- a/include/uapi/linux/mptcp.h
> +++ b/include/uapi/linux/mptcp.h
> @@ -12,6 +12,7 @@
>  #include <linux/in.h>		/* for sockaddr_in			*/
>  #include <linux/in6.h>		/* for sockaddr_in6			*/
>  #include <linux/socket.h>	/* for sockaddr_storage and sa_family	*/
> +#include <linux/tcp.h>		/* for tcp_info				*/
>  
>  #define MPTCP_SUBFLOW_FLAG_MCAP_REM		_BITUL(0)
>  #define MPTCP_SUBFLOW_FLAG_MCAP_LOC		_BITUL(1)
> @@ -244,9 +245,24 @@ struct mptcp_subflow_addrs {
>  	};
>  };
>  
> +struct mptcp_subflow_info {
> +	__u32				id;
> +	struct mptcp_subflow_addrs	addrs;
> +};
> +
> +/* struct subflow_info is not supposed nor allowed to grow in
> + * future versions.
> + * If need will arise, a new socket option should be added.
> + */
> +struct mptcp_subflow_full_info {
> +	struct mptcp_subflow_info	subflow_info;
> +	struct tcp_info			tcp_info;
> +};

I dislike this constraint.

Why not do something like this:

struct mptcp_subflow_full_info {
	__u32		size_subflow_full_info;         /* size of this structure in userspace */
	__u32           num_subflows_user;              /* max subflows that userspace is interested in */
	__u32           num_subflows_kern;              /* must be 0, set by kernel (real subflow count) */
	__u32		num_subflows_copied;		/* must be 0, set by kernel (number of subflow infos copied back)
        __u32           size_sfinfo_kernel;		/* must be 0, set by kernel */
        __u32           size_sfinfo_user;
        __u32           size_tcpinfo_kernel;            /* must be 0, set by kernel */
        __u32           size_tcpinfo_user;
	__aligned_u64	subflow_info_addr;
	__aligned_u64	tcp_info_addr;
};

userspace does:

x = calloc(sizeof(struct mptcp_subflow_info), 42);
y = calloc(sizeof(struct tcp_info), 42);

struct mptcp_subflow_full_info {
	.size_subflow_full_info = sizeof(struct mptcp_subflow_full_info),
	.num_subflows_user = 42,
	.size_sfinfo_user = sizeof(struct mptcp_subflow_info),
	.size_tcpinfo_user = sizeof(struct mptcp_subflow_info),
	.subflow_info_addr = (u64)x,
	.tcp_info_addr = (u64)y,
};

kernel does:
1. put_user() the real sizes uses by the kernel
2. put_user() the real subflow count
3. copy subflow_info_addr and tcp_info_addr addresses
4. treat as userspace pointers

for each subflow, copy tcpinfo and subflow info to the
two arrays provided by userspace.

Kernel truncates copied data via size_sfinfo_user/size_tcpinfo_user so
that new kernel won't populate fields that don't exist in userspace.

Kernel stops copying after 'num_subflows_user' or 'num_subflows_kern',
whatever comes first and updates num_subflows_copied to the real copied
value.

This allows userspace to discover when kernel had more subflows
but could not place the data due to lack of space in the
userspace-provided arrays.

This is more complicated but no need to add new MPTCP_FULL_INFO_V2/V3/V4
etc. in the future.

What do you think?
Re: [PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Matthieu Baerts 1 year, 3 months ago
Hi Florian,

Thank you for your nice review!

On 23/05/2023 20:25, Florian Westphal wrote:
> Paolo Abeni <pabeni@redhat.com> wrote:
>> Some user-space applications want to monitor the subflows utilization.
>>
>> Dumping the per subflow tcp_info is not enough, as the PM could close
>> and re-create the subflows under-the-hood, fooling the accounting.
>> Even checking the src/dst addresses used by each subflow could not
>> be enough, because new subflows could re-use the same address/port of
>> the just closed one.
>>
>> This patch introduces a new socket option, allow dumping all the relevant
>> information all-at-once (everything, everywhere...), in a consistent manner.
>>
>> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
>> ---
>> v2 -> v3:
>>  - added missing changelog (oops)
>> ---
>>  include/uapi/linux/mptcp.h | 16 ++++++++
>>  net/mptcp/sockopt.c        | 75 ++++++++++++++++++++++++++++++++++++++
>>  2 files changed, 91 insertions(+)
>>
>> diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h
>> index 32af2d278cb4..f4f42d88e58b 100644
>> --- a/include/uapi/linux/mptcp.h
>> +++ b/include/uapi/linux/mptcp.h
>> @@ -12,6 +12,7 @@
>>  #include <linux/in.h>		/* for sockaddr_in			*/
>>  #include <linux/in6.h>		/* for sockaddr_in6			*/
>>  #include <linux/socket.h>	/* for sockaddr_storage and sa_family	*/
>> +#include <linux/tcp.h>		/* for tcp_info				*/
>>  
>>  #define MPTCP_SUBFLOW_FLAG_MCAP_REM		_BITUL(0)
>>  #define MPTCP_SUBFLOW_FLAG_MCAP_LOC		_BITUL(1)
>> @@ -244,9 +245,24 @@ struct mptcp_subflow_addrs {
>>  	};
>>  };
>>  
>> +struct mptcp_subflow_info {
>> +	__u32				id;
>> +	struct mptcp_subflow_addrs	addrs;
>> +};
>> +
>> +/* struct subflow_info is not supposed nor allowed to grow in
>> + * future versions.
>> + * If need will arise, a new socket option should be added.
>> + */
>> +struct mptcp_subflow_full_info {
>> +	struct mptcp_subflow_info	subflow_info;
>> +	struct tcp_info			tcp_info;
>> +};
> 
> I dislike this constraint.
> 
> Why not do something like this:
> 
> struct mptcp_subflow_full_info {

(If we add mptcp_info (cf Paolo's email), better to strip 'subflow')

> 	__u32		size_subflow_full_info;         /* size of this structure in userspace */

Why do we need this field? Can we not use the option length (int __user
*optlen) provided by the userspace?

> 	__u32           num_subflows_user;              /* max subflows that userspace is interested in */
> 	__u32           num_subflows_kern;              /* must be 0, set by kernel (real subflow count) */
> 	__u32		num_subflows_copied;		/* must be 0, set by kernel (number of subflow infos copied back)
>         __u32           size_sfinfo_kernel;		/* must be 0, set by kernel */
>         __u32           size_sfinfo_user;
>         __u32           size_tcpinfo_kernel;            /* must be 0, set by kernel */
>         __u32           size_tcpinfo_user;

Do we need to have the kernel and user size in different fields?
Is it not enough have:

  num_subflows;          /* will be set by the kernel */
  num_subflows_copied;   /* max for the user, kernel put what it did */
  size_sfinfo;           /* user set it, kernel put what it used: min */
  size_tcpinfo;          /* same */

> 	__aligned_u64	subflow_info_addr;
> 	__aligned_u64	tcp_info_addr;
> };
> 
> userspace does:
> 
> x = calloc(sizeof(struct mptcp_subflow_info), 42);
> y = calloc(sizeof(struct tcp_info), 42);
> 
> struct mptcp_subflow_full_info {
> 	.size_subflow_full_info = sizeof(struct mptcp_subflow_full_info),
> 	.num_subflows_user = 42,
> 	.size_sfinfo_user = sizeof(struct mptcp_subflow_info),
> 	.size_tcpinfo_user = sizeof(struct mptcp_subflow_info),
> 	.subflow_info_addr = (u64)x,
> 	.tcp_info_addr = (u64)y,
> };
> 
> kernel does:
> 1. put_user() the real sizes uses by the kernel
> 2. put_user() the real subflow count
> 3. copy subflow_info_addr and tcp_info_addr addresses
> 4. treat as userspace pointers
> 
> for each subflow, copy tcpinfo and subflow info to the
> two arrays provided by userspace.
> 
> Kernel truncates copied data via size_sfinfo_user/size_tcpinfo_user so
> that new kernel won't populate fields that don't exist in userspace.
> 
> Kernel stops copying after 'num_subflows_user' or 'num_subflows_kern',
> whatever comes first and updates num_subflows_copied to the real copied
> value.
> 
> This allows userspace to discover when kernel had more subflows
> but could not place the data due to lack of space in the
> userspace-provided arrays.
> 
> This is more complicated but no need to add new MPTCP_FULL_INFO_V2/V3/V4
> etc. in the future.

If we add mptcp_info structure as mentioned by Paolo, we are getting
very close the the getsockopt(MPTCP_INFO) from the fork kernel, see the
section "Get detailed information of your subflows":

https://multipath-tcp.org/pmwiki.php/Users/ConfigureMPTCP

And the kernel header:

https://github.com/multipath-tcp/mptcp/blob/mptcp_trunk/include/uapi/linux/tcp.h#L321-L366

> What do you think?

If we want to be even more future prove, why not having something more
flexible where the userspace puts flags of what it wants and then there
is a kind of TLV structure? Maybe it would be too complex to read/write?


  struct mptcp_tlv_info {
      __u32 type;
      __u32 length;
      __aligned_u64 value;
  };

  struct mptcp_full_info {
      __u32 flags;
      __u32 num_subflows;
      __u32 num_subflows_copied;
      struct mptcp_tlv_info[];   /* number has to be linked to flags */
  };


Maybe it would be good to add a size for the subflow info structure: if
we use such TLV structure, for info around subflows, we will need to set
at least the ID for each subflow (maybe more later). We might then need:

  struct mptcp_full_info {
      (...)
      __u32 size_mptcp_subflow_info;
      (...)
  };

  struct mptcp_subflow_info {
      __u32 id;
  };

  struct mptcp_subflow_addrs {
      struct mptcp_subflow_info  info;
      struct mptcp_subflow_addrs addrs;
  };

  struct mptcp_subflow_tcp_info {
      struct mptcp_subflow_info info;
      struct tcp_info           tcp_info;
  };

Again, just a quick idea, I didn't investigate more. With that, we will
likely not need more getsockopt() to get info about the MPTCP connection
and its subflows, just an all in one getsockopt().

I'm just trying to reacting quickly before going into a direction :)

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
Re: [PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Florian Westphal 1 year, 3 months ago
Matthieu Baerts <matthieu.baerts@tessares.net> wrote:
> On 23/05/2023 20:25, Florian Westphal wrote:
> > 	__u32		size_subflow_full_info;         /* size of this structure in userspace */
> 
> Why do we need this field? Can we not use the option length (int __user
> *optlen) provided by the userspace?

Right, yes, we can (and should) use __user *optlen instead
of this explicit member.

> >         __u32           size_sfinfo_kernel;		/* must be 0, set by kernel */
> >         __u32           size_sfinfo_user;
> >         __u32           size_tcpinfo_kernel;            /* must be 0, set by kernel */
> >         __u32           size_tcpinfo_user;
> 
> Do we need to have the kernel and user size in different fields?
> Is it not enough have:
> 
>   num_subflows;          /* will be set by the kernel */
>   num_subflows_copied;   /* max for the user, kernel put what it did */
>   size_sfinfo;           /* user set it, kernel put what it used: min */
>   size_tcpinfo;          /* same */

Yes, that would work too: kernel updates value to what its using.

I have no preference.  I used extra fields to better document
that this is filled in by the kernel.

I'll let Paolo make the call.

> If we add mptcp_info structure as mentioned by Paolo, we are getting
> very close the the getsockopt(MPTCP_INFO) from the fork kernel, see the
> section "Get detailed information of your subflows":
> 
> https://multipath-tcp.org/pmwiki.php/Users/ConfigureMPTCP
> 
> And the kernel header:
> 
> https://github.com/multipath-tcp/mptcp/blob/mptcp_trunk/include/uapi/linux/tcp.h#L321-L366

Right, this is similar.

> If we want to be even more future prove, why not having something more
> flexible where the userspace puts flags of what it wants and then there
> is a kind of TLV structure? Maybe it would be too complex to read/write?
> 
> 
>   struct mptcp_tlv_info {
>       __u32 type;
>       __u32 length;
>       __aligned_u64 value;
>   };
> 
>   struct mptcp_full_info {
>       __u32 flags;
>       __u32 num_subflows;
>       __u32 num_subflows_copied;
>       struct mptcp_tlv_info[];   /* number has to be linked to flags */
>   };

Hmm, I think it would be better to reuse an existing scheme
and e.g. return a netlink attribute blob in such a case,
this would also allow sharing with the diag interface/functions.
Re: [PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Matthieu Baerts 1 year, 3 months ago
Hi Florian,

Thank you for your replies!

On 24/05/2023 12:04, Florian Westphal wrote:
> Matthieu Baerts <matthieu.baerts@tessares.net> wrote:
>> If we want to be even more future prove, why not having something more
>> flexible where the userspace puts flags of what it wants and then there
>> is a kind of TLV structure? Maybe it would be too complex to read/write?
>>
>>
>>   struct mptcp_tlv_info {
>>       __u32 type;
>>       __u32 length;
>>       __aligned_u64 value;
>>   };
>>
>>   struct mptcp_full_info {
>>       __u32 flags;
>>       __u32 num_subflows;
>>       __u32 num_subflows_copied;
>>       struct mptcp_tlv_info[];   /* number has to be linked to flags */
>>   };
> 
> Hmm, I think it would be better to reuse an existing scheme
> and e.g. return a netlink attribute blob in such a case,
> this would also allow sharing with the diag interface/functions.

Ah yes, good idea, I didn't think about that.

But I don't know what's best for the userspace: parsing netlink blob or
a specific structure with a size that can be expended. Netlink blob
sounds more future prove and probably easier to maintain (if it is OK to
use that with getsockopt()).

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
Re: [PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Paolo Abeni 1 year, 3 months ago
On Wed, 2023-05-24 at 10:13 +0200, Matthieu Baerts wrote:
> Hi Florian,
> 
> Thank you for your nice review!
> 
> On 23/05/2023 20:25, Florian Westphal wrote:
> > Paolo Abeni <pabeni@redhat.com> wrote:
> > > Some user-space applications want to monitor the subflows utilization.
> > > 
> > > Dumping the per subflow tcp_info is not enough, as the PM could close
> > > and re-create the subflows under-the-hood, fooling the accounting.
> > > Even checking the src/dst addresses used by each subflow could not
> > > be enough, because new subflows could re-use the same address/port of
> > > the just closed one.
> > > 
> > > This patch introduces a new socket option, allow dumping all the relevant
> > > information all-at-once (everything, everywhere...), in a consistent manner.
> > > 
> > > Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> > > ---
> > > v2 -> v3:
> > >  - added missing changelog (oops)
> > > ---
> > >  include/uapi/linux/mptcp.h | 16 ++++++++
> > >  net/mptcp/sockopt.c        | 75 ++++++++++++++++++++++++++++++++++++++
> > >  2 files changed, 91 insertions(+)
> > > 
> > > diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h
> > > index 32af2d278cb4..f4f42d88e58b 100644
> > > --- a/include/uapi/linux/mptcp.h
> > > +++ b/include/uapi/linux/mptcp.h
> > > @@ -12,6 +12,7 @@
> > >  #include <linux/in.h>		/* for sockaddr_in			*/
> > >  #include <linux/in6.h>		/* for sockaddr_in6			*/
> > >  #include <linux/socket.h>	/* for sockaddr_storage and sa_family	*/
> > > +#include <linux/tcp.h>		/* for tcp_info				*/
> > >  
> > >  #define MPTCP_SUBFLOW_FLAG_MCAP_REM		_BITUL(0)
> > >  #define MPTCP_SUBFLOW_FLAG_MCAP_LOC		_BITUL(1)
> > > @@ -244,9 +245,24 @@ struct mptcp_subflow_addrs {
> > >  	};
> > >  };
> > >  
> > > +struct mptcp_subflow_info {
> > > +	__u32				id;
> > > +	struct mptcp_subflow_addrs	addrs;
> > > +};
> > > +
> > > +/* struct subflow_info is not supposed nor allowed to grow in
> > > + * future versions.
> > > + * If need will arise, a new socket option should be added.
> > > + */
> > > +struct mptcp_subflow_full_info {
> > > +	struct mptcp_subflow_info	subflow_info;
> > > +	struct tcp_info			tcp_info;
> > > +};
> > 
> > I dislike this constraint.
> > 
> > Why not do something like this:
> > 
> > struct mptcp_subflow_full_info {
> 
> (If we add mptcp_info (cf Paolo's email), better to strip 'subflow')
> 
> > 	__u32		size_subflow_full_info;         /* size of this structure in userspace */
> 
> Why do we need this field? Can we not use the option length (int __user
> *optlen) provided by the userspace?

With this we can append arbitrary/variable size mptcp_info at the end.

> 
> > 	__u32           num_subflows_user;              /* max subflows that userspace is interested in */
> > 	__u32           num_subflows_kern;              /* must be 0, set by kernel (real subflow count) */
> > 	__u32		num_subflows_copied;		/* must be 0, set by kernel (number of subflow infos copied back)
> >         __u32           size_sfinfo_kernel;		/* must be 0, set by kernel */
> >         __u32           size_sfinfo_user;
> >         __u32           size_tcpinfo_kernel;            /* must be 0, set by kernel */
> >         __u32           size_tcpinfo_user;
> 
> Do we need to have the kernel and user size in different fields?

If we keep, we can re-use the existing code to manipulate this struct.
Also is consistent with other socket option.


> > This is more complicated but no need to add new MPTCP_FULL_INFO_V2/V3/V4
> > etc. in the future.
> 
> If we add mptcp_info structure as mentioned by Paolo, we are getting
> very close the the getsockopt(MPTCP_INFO) from the fork kernel, see the
> section "Get detailed information of your subflows":
> 
> https://multipath-tcp.org/pmwiki.php/Users/ConfigureMPTCP
> 
> And the kernel header:
> 
> https://github.com/multipath-tcp/mptcp/blob/mptcp_trunk/include/uapi/linux/tcp.h#L321-L366
> 
> > What do you think?
> 
> If we want to be even more future prove, why not having something more
> flexible where the userspace puts flags of what it wants and then there
> is a kind of TLV structure? Maybe it would be too complex to read/write?
> 
> 
>   struct mptcp_tlv_info {
>       __u32 type;
>       __u32 length;
>       __aligned_u64 value;
>   };
> 
>   struct mptcp_full_info {
>       __u32 flags;
>       __u32 num_subflows;
>       __u32 num_subflows_copied;
>       struct mptcp_tlv_info[];   /* number has to be linked to flags */
>   };
> 
> Maybe it would be good to add a size for the subflow info structure: if
> we use such TLV structure, for info around subflows, we will need to set
> at least the ID for each subflow (maybe more later). We might then need:
> 
>   struct mptcp_full_info {
>       (...)
>       __u32 size_mptcp_subflow_info;
>       (...)
>   };
> 
>   struct mptcp_subflow_info {
>       __u32 id;
>   };
> 
>   struct mptcp_subflow_addrs {
>       struct mptcp_subflow_info  info;
>       struct mptcp_subflow_addrs addrs;
>   };
> 
>   struct mptcp_subflow_tcp_info {
>       struct mptcp_subflow_info info;
>       struct tcp_info           tcp_info;
>   };
> 
> Again, just a quick idea, I didn't investigate more. With that, we will
> likely not need more getsockopt() to get info about the MPTCP connection
> and its subflows, just an all in one getsockopt().
> 
> I'm just trying to reacting quickly before going into a direction :)

Uhm... I think TLV are not in the right direction: away from the
current convention for variable size/changing struct. If use TLV we
could as well move to NL, which will be again inconsistent to fetch
such kind of info IMHO.

I think it's preferable to keep the sockopt API self-consistent then be
aligned with out-of-tree.

The layout proposed by Florian fits what we already have.

With some little field re-order I can avoid code duplication to
parse/store the initial header.

Cheers,

Paolo
Re: [PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Matthieu Baerts 1 year, 3 months ago
Hi Paolo,

On 24/05/2023 10:53, Paolo Abeni wrote:
> On Wed, 2023-05-24 at 10:13 +0200, Matthieu Baerts wrote:
>> Hi Florian,
>>
>> Thank you for your nice review!
>>
>> On 23/05/2023 20:25, Florian Westphal wrote:
>>> Paolo Abeni <pabeni@redhat.com> wrote:
>>>> Some user-space applications want to monitor the subflows utilization.
>>>>
>>>> Dumping the per subflow tcp_info is not enough, as the PM could close
>>>> and re-create the subflows under-the-hood, fooling the accounting.
>>>> Even checking the src/dst addresses used by each subflow could not
>>>> be enough, because new subflows could re-use the same address/port of
>>>> the just closed one.
>>>>
>>>> This patch introduces a new socket option, allow dumping all the relevant
>>>> information all-at-once (everything, everywhere...), in a consistent manner.
>>>>
>>>> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
>>>> ---
>>>> v2 -> v3:
>>>>  - added missing changelog (oops)
>>>> ---
>>>>  include/uapi/linux/mptcp.h | 16 ++++++++
>>>>  net/mptcp/sockopt.c        | 75 ++++++++++++++++++++++++++++++++++++++
>>>>  2 files changed, 91 insertions(+)
>>>>
>>>> diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h
>>>> index 32af2d278cb4..f4f42d88e58b 100644
>>>> --- a/include/uapi/linux/mptcp.h
>>>> +++ b/include/uapi/linux/mptcp.h
>>>> @@ -12,6 +12,7 @@
>>>>  #include <linux/in.h>		/* for sockaddr_in			*/
>>>>  #include <linux/in6.h>		/* for sockaddr_in6			*/
>>>>  #include <linux/socket.h>	/* for sockaddr_storage and sa_family	*/
>>>> +#include <linux/tcp.h>		/* for tcp_info				*/
>>>>  
>>>>  #define MPTCP_SUBFLOW_FLAG_MCAP_REM		_BITUL(0)
>>>>  #define MPTCP_SUBFLOW_FLAG_MCAP_LOC		_BITUL(1)
>>>> @@ -244,9 +245,24 @@ struct mptcp_subflow_addrs {
>>>>  	};
>>>>  };
>>>>  
>>>> +struct mptcp_subflow_info {
>>>> +	__u32				id;
>>>> +	struct mptcp_subflow_addrs	addrs;
>>>> +};
>>>> +
>>>> +/* struct subflow_info is not supposed nor allowed to grow in
>>>> + * future versions.
>>>> + * If need will arise, a new socket option should be added.
>>>> + */
>>>> +struct mptcp_subflow_full_info {
>>>> +	struct mptcp_subflow_info	subflow_info;
>>>> +	struct tcp_info			tcp_info;
>>>> +};
>>>
>>> I dislike this constraint.
>>>
>>> Why not do something like this:
>>>
>>> struct mptcp_subflow_full_info {
>>
>> (If we add mptcp_info (cf Paolo's email), better to strip 'subflow')
>>
>>> 	__u32		size_subflow_full_info;         /* size of this structure in userspace */
>>
>> Why do we need this field? Can we not use the option length (int __user
>> *optlen) provided by the userspace?
> 
> With this we can append arbitrary/variable size mptcp_info at the end.

I guess either we use a dedicated field for mptcp_info or we infer its
value by looking at size_full_info or optlen. It looks clearer to me
from the userspace point of view to have a dedicated size for mptcp_info
than giving twice sizeof(mptcp_subflow_tcp_info) but I'm probably
missing something :)

>>> 	__u32           num_subflows_user;              /* max subflows that userspace is interested in */
>>> 	__u32           num_subflows_kern;              /* must be 0, set by kernel (real subflow count) */
>>> 	__u32		num_subflows_copied;		/* must be 0, set by kernel (number of subflow infos copied back)
>>>         __u32           size_sfinfo_kernel;		/* must be 0, set by kernel */
>>>         __u32           size_sfinfo_user;
>>>         __u32           size_tcpinfo_kernel;            /* must be 0, set by kernel */
>>>         __u32           size_tcpinfo_user;
>>
>> Do we need to have the kernel and user size in different fields?
> 
> If we keep, we can re-use the existing code to manipulate this struct.
> Also is consistent with other socket option.

If we don't need them, we don't need to be consistent, especially if we
plan to deprecate the MPTCP_TCP_INFO and MPTCP_SUBFLOW_ADDRS sockopt at
some points :)

But if it allows to re-use the existing code and not deprecate the two
sockopt, I understand we want to do that!

>>> This is more complicated but no need to add new MPTCP_FULL_INFO_V2/V3/V4
>>> etc. in the future.
>>
>> If we add mptcp_info structure as mentioned by Paolo, we are getting
>> very close the the getsockopt(MPTCP_INFO) from the fork kernel, see the
>> section "Get detailed information of your subflows":
>>
>> https://multipath-tcp.org/pmwiki.php/Users/ConfigureMPTCP
>>
>> And the kernel header:
>>
>> https://github.com/multipath-tcp/mptcp/blob/mptcp_trunk/include/uapi/linux/tcp.h#L321-L366
>>
>>> What do you think?
>>
>> If we want to be even more future prove, why not having something more
>> flexible where the userspace puts flags of what it wants and then there
>> is a kind of TLV structure? Maybe it would be too complex to read/write?
>>
>>
>>   struct mptcp_tlv_info {
>>       __u32 type;
>>       __u32 length;
>>       __aligned_u64 value;
>>   };
>>
>>   struct mptcp_full_info {
>>       __u32 flags;
>>       __u32 num_subflows;
>>       __u32 num_subflows_copied;
>>       struct mptcp_tlv_info[];   /* number has to be linked to flags */
>>   };
>>
>> Maybe it would be good to add a size for the subflow info structure: if
>> we use such TLV structure, for info around subflows, we will need to set
>> at least the ID for each subflow (maybe more later). We might then need:
>>
>>   struct mptcp_full_info {
>>       (...)
>>       __u32 size_mptcp_subflow_info;
>>       (...)
>>   };
>>
>>   struct mptcp_subflow_info {
>>       __u32 id;
>>   };
>>
>>   struct mptcp_subflow_addrs {
>>       struct mptcp_subflow_info  info;
>>       struct mptcp_subflow_addrs addrs;
>>   };
>>
>>   struct mptcp_subflow_tcp_info {
>>       struct mptcp_subflow_info info;
>>       struct tcp_info           tcp_info;
>>   };
>>
>> Again, just a quick idea, I didn't investigate more. With that, we will
>> likely not need more getsockopt() to get info about the MPTCP connection
>> and its subflows, just an all in one getsockopt().
>>
>> I'm just trying to reacting quickly before going into a direction :)
> 
> Uhm... I think TLV are not in the right direction: away from the
> current convention for variable size/changing struct. If use TLV we
> could as well move to NL, which will be again inconsistent to fetch
> such kind of info IMHO.
> 
> I think it's preferable to keep the sockopt API self-consistent then be
> aligned with out-of-tree.
> 
> The layout proposed by Florian fits what we already have.
> 
> With some little field re-order I can avoid code duplication to
> parse/store the initial header.

I see, thank you for the explanation!

I was suggesting the TLV structure because maybe the userspace doesn't
need everything, e.g. the different addresses, maybe just the ID per
subflow is enough? But because we only copy info and we don't compute
stuff, it is fine to receive everything.

Also the other advantage is to be able to get more info but I suppose we
can:
- add more stuff in mptcp_info for the MPTCP connection
- add more stuff in mptcp_subflow_info for per subflow info.

So as long as we keep a "generic" subflow info structure like you did in
your patch v3 2/6 and not specific to the addresses only, I think
indeed, we don't need TLVs.

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
Re: [PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Paolo Abeni 1 year, 3 months ago
On Tue, 2023-05-23 at 20:25 +0200, Florian Westphal wrote:
> Paolo Abeni <pabeni@redhat.com> wrote:
> > Some user-space applications want to monitor the subflows utilization.
> > 
> > Dumping the per subflow tcp_info is not enough, as the PM could close
> > and re-create the subflows under-the-hood, fooling the accounting.
> > Even checking the src/dst addresses used by each subflow could not
> > be enough, because new subflows could re-use the same address/port of
> > the just closed one.
> > 
> > This patch introduces a new socket option, allow dumping all the relevant
> > information all-at-once (everything, everywhere...), in a consistent manner.
> > 
> > Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> > ---
> > v2 -> v3:
> >  - added missing changelog (oops)
> > ---
> >  include/uapi/linux/mptcp.h | 16 ++++++++
> >  net/mptcp/sockopt.c        | 75 ++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 91 insertions(+)
> > 
> > diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h
> > index 32af2d278cb4..f4f42d88e58b 100644
> > --- a/include/uapi/linux/mptcp.h
> > +++ b/include/uapi/linux/mptcp.h
> > @@ -12,6 +12,7 @@
> >  #include <linux/in.h>		/* for sockaddr_in			*/
> >  #include <linux/in6.h>		/* for sockaddr_in6			*/
> >  #include <linux/socket.h>	/* for sockaddr_storage and sa_family	*/
> > +#include <linux/tcp.h>		/* for tcp_info				*/
> >  
> >  #define MPTCP_SUBFLOW_FLAG_MCAP_REM		_BITUL(0)
> >  #define MPTCP_SUBFLOW_FLAG_MCAP_LOC		_BITUL(1)
> > @@ -244,9 +245,24 @@ struct mptcp_subflow_addrs {
> >  	};
> >  };
> >  
> > +struct mptcp_subflow_info {
> > +	__u32				id;
> > +	struct mptcp_subflow_addrs	addrs;
> > +};
> > +
> > +/* struct subflow_info is not supposed nor allowed to grow in
> > + * future versions.
> > + * If need will arise, a new socket option should be added.
> > + */
> > +struct mptcp_subflow_full_info {
> > +	struct mptcp_subflow_info	subflow_info;
> > +	struct tcp_info			tcp_info;
> > +};
> 
> I dislike this constraint.
> 
> Why not do something like this:
> 
> struct mptcp_subflow_full_info {
> 	__u32		size_subflow_full_info;         /* size of this structure in userspace */
> 	__u32           num_subflows_user;              /* max subflows that userspace is interested in */
> 	__u32           num_subflows_kern;              /* must be 0, set by kernel (real subflow count) */
> 	__u32		num_subflows_copied;		/* must be 0, set by kernel (number of subflow infos copied back)
>         __u32           size_sfinfo_kernel;		/* must be 0, set by kernel */
>         __u32           size_sfinfo_user;
>         __u32           size_tcpinfo_kernel;            /* must be 0, set by kernel */
>         __u32           size_tcpinfo_user;
> 	__aligned_u64	subflow_info_addr;
> 	__aligned_u64	tcp_info_addr;
> };
> 
> userspace does:
> 
> x = calloc(sizeof(struct mptcp_subflow_info), 42);
> y = calloc(sizeof(struct tcp_info), 42);
> 
> struct mptcp_subflow_full_info {
> 	.size_subflow_full_info = sizeof(struct mptcp_subflow_full_info),
> 	.num_subflows_user = 42,
> 	.size_sfinfo_user = sizeof(struct mptcp_subflow_info),
> 	.size_tcpinfo_user = sizeof(struct mptcp_subflow_info),
> 	.subflow_info_addr = (u64)x,
> 	.tcp_info_addr = (u64)y,
> };
> 
> kernel does:
> 1. put_user() the real sizes uses by the kernel
> 2. put_user() the real subflow count
> 3. copy subflow_info_addr and tcp_info_addr addresses
> 4. treat as userspace pointers
> 
> for each subflow, copy tcpinfo and subflow info to the
> two arrays provided by userspace.
> 
> Kernel truncates copied data via size_sfinfo_user/size_tcpinfo_user so
> that new kernel won't populate fields that don't exist in userspace.
> 
> Kernel stops copying after 'num_subflows_user' or 'num_subflows_kern',
> whatever comes first and updates num_subflows_copied to the real copied
> value.
> 
> This allows userspace to discover when kernel had more subflows
> but could not place the data due to lack of space in the
> userspace-provided arrays.
> 
> This is more complicated but no need to add new MPTCP_FULL_INFO_V2/V3/V4
> etc. in the future.
> 
> What do you think?

I ended-up with the current code trying to re-use as much as possible
from the existing infra - specifically the
mptcp_get_subflow_data()/mptcp_put_subflow_data() helpers.

I agree the constraint on mptcp_subflow_full_info is not nice,
especially if we want to include subflow level indormation alike
local/remote address id, flags, etc...

Isn't num_subflows_copied always implied? == min(num_subflows_user,
num_subflows_kern).

Otherwise LGTM, I'll try to have a spin.

Thanks!

Paolo
Re: [PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Florian Westphal 1 year, 3 months ago
Paolo Abeni <pabeni@redhat.com> wrote:
> Isn't num_subflows_copied always implied? == min(num_subflows_user,
> num_subflows_kern).

Right, userspace can infer the correct number, i.e.
num_subflows_kern would always be the "actual" used number.

num_subflows_user > num_subflows_kern:

Userspace can safely access "num_subflows_kern" entries
(contain no garbage).

num_subflows_user < num_subflows_kern:
Userspace can safely access "num_subflows_user" entries
(info arrays did not have enough space for all subflows).

I added the "num_subflows_copied" for ease-of-use on userspace
side but I agree that its not required and userspace has
enough info to figure out which upper cap to use.

> Otherwise LGTM, I'll try to have a spin.

Thanks Paolo.
Re: [PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Matthieu Baerts 1 year, 3 months ago
Hi Florian, Paolo,

On 24/05/2023 11:56, Florian Westphal wrote:
> Paolo Abeni <pabeni@redhat.com> wrote:
>> Isn't num_subflows_copied always implied? == min(num_subflows_user,
>> num_subflows_kern).
> 
> Right, userspace can infer the correct number, i.e.
> num_subflows_kern would always be the "actual" used number.
> 
> num_subflows_user > num_subflows_kern:
> 
> Userspace can safely access "num_subflows_kern" entries
> (contain no garbage).
> 
> num_subflows_user < num_subflows_kern:
> Userspace can safely access "num_subflows_user" entries
> (info arrays did not have enough space for all subflows).
> 
> I added the "num_subflows_copied" for ease-of-use on userspace
> side but I agree that its not required and userspace has
> enough info to figure out which upper cap to use.

If I understand properly, it means that num_subflows_user and _kern will
only be used to know the size of the arrays:

- num_subflows_user: size of the arrays in the buffer
- num_subflows_kern: what has been written by the kernel, max _user

I think it is still important to have somewhere a num_subflows field to
know how many subflows are attached to an MPTCP connection (also for the
userspace to know if it missed some info because it gave a too small
buffer).

"struct mptcp_info" has a "subflows" field but only counting the
additional subflows so you never know the actual number of subflows :)

Or we add a num_subflows in "struct mptcp_info"?

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
Re: [PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Florian Westphal 1 year, 3 months ago
Matthieu Baerts <matthieu.baerts@tessares.net> wrote:
> > I added the "num_subflows_copied" for ease-of-use on userspace
> > side but I agree that its not required and userspace has
> > enough info to figure out which upper cap to use.
> 
> If I understand properly, it means that num_subflows_user and _kern will
> only be used to know the size of the arrays:
> 
> - num_subflows_user: size of the arrays in the buffer
> - num_subflows_kern: what has been written by the kernel, max _user

This is why I had the '_copied' in my proposal :-)

With only _user and _kern:

_user: size of the arrays in the buffer
_kern: subflow count of the kernel, i.e. can be larger than _user.

> I think it is still important to have somewhere a num_subflows field to
> know how many subflows are attached to an MPTCP connection (also for the
> userspace to know if it missed some info because it gave a too small
> buffer).

Yes, userspace must be able to infer that it only got partial
information due to lack of space.

E.g. if userspace expects a maximum amount of 16 subflows but connection
has 240 subflows then num_subflows_kern is 240 and _user is 16.

Userspace can only access up to 16 (since thats what it
provided/allocated).

The _copied proposal would have made this easier on userspace side
(_user is the allocated space, _kern what the kernel would like (real
count), and _copied what was written out).

But as Paolo said userspace can infer the valid count by checking
if _kern > _user, so it does:

bool truncated = kern > user;
subflows_copied = truncated ? user : kern;
Re: [PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Matthieu Baerts 1 year, 3 months ago
Hi Florian,

On 24/05/2023 14:22, Florian Westphal wrote:
> Matthieu Baerts <matthieu.baerts@tessares.net> wrote:
>>> I added the "num_subflows_copied" for ease-of-use on userspace
>>> side but I agree that its not required and userspace has
>>> enough info to figure out which upper cap to use.
>>
>> If I understand properly, it means that num_subflows_user and _kern will
>> only be used to know the size of the arrays:
>>
>> - num_subflows_user: size of the arrays in the buffer
>> - num_subflows_kern: what has been written by the kernel, max _user
> 
> This is why I had the '_copied' in my proposal :-)
> 
> With only _user and _kern:
> 
> _user: size of the arrays in the buffer
> _kern: subflow count of the kernel, i.e. can be larger than _user.

Thank you, that's clearer, so _kern would be the subflow count, not just
what has been copied.

>> I think it is still important to have somewhere a num_subflows field to
>> know how many subflows are attached to an MPTCP connection (also for the
>> userspace to know if it missed some info because it gave a too small
>> buffer).
> 
> Yes, userspace must be able to infer that it only got partial
> information due to lack of space.
> 
> E.g. if userspace expects a maximum amount of 16 subflows but connection
> has 240 subflows then num_subflows_kern is 240 and _user is 16.
> 
> Userspace can only access up to 16 (since thats what it
> provided/allocated).
> 
> The _copied proposal would have made this easier on userspace side
> (_user is the allocated space, _kern what the kernel would like (real
> count), and _copied what was written out).
> 
> But as Paolo said userspace can infer the valid count by checking
> if _kern > _user, so it does:
> 
> bool truncated = kern > user;
> subflows_copied = truncated ? user : kern;

OK then it is fine if we can use min(_user, _kern) to know the number of
subflows written by the kernel and '_kern' for the actual number of
subflows attached to an MPTCP connection.

Maybe we should rename 'num_subflows_kern' to 'num_subflows'? and even
'num_subflows_user' to 'num_subflows_buffer' or 'size_array(s)'?

Or maybe enough with the comments from the example you provided?

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
Re: [PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Paolo Abeni 1 year, 3 months ago
On Wed, 2023-05-24 at 08:34 +0200, Paolo Abeni wrote:
> On Tue, 2023-05-23 at 20:25 +0200, Florian Westphal wrote:
> > Paolo Abeni <pabeni@redhat.com> wrote:
> > > Some user-space applications want to monitor the subflows utilization.
> > > 
> > > Dumping the per subflow tcp_info is not enough, as the PM could close
> > > and re-create the subflows under-the-hood, fooling the accounting.
> > > Even checking the src/dst addresses used by each subflow could not
> > > be enough, because new subflows could re-use the same address/port of
> > > the just closed one.
> > > 
> > > This patch introduces a new socket option, allow dumping all the relevant
> > > information all-at-once (everything, everywhere...), in a consistent manner.
> > > 
> > > Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> > > ---
> > > v2 -> v3:
> > >  - added missing changelog (oops)
> > > ---
> > >  include/uapi/linux/mptcp.h | 16 ++++++++
> > >  net/mptcp/sockopt.c        | 75 ++++++++++++++++++++++++++++++++++++++
> > >  2 files changed, 91 insertions(+)
> > > 
> > > diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h
> > > index 32af2d278cb4..f4f42d88e58b 100644
> > > --- a/include/uapi/linux/mptcp.h
> > > +++ b/include/uapi/linux/mptcp.h
> > > @@ -12,6 +12,7 @@
> > >  #include <linux/in.h>		/* for sockaddr_in			*/
> > >  #include <linux/in6.h>		/* for sockaddr_in6			*/
> > >  #include <linux/socket.h>	/* for sockaddr_storage and sa_family	*/
> > > +#include <linux/tcp.h>		/* for tcp_info				*/
> > >  
> > >  #define MPTCP_SUBFLOW_FLAG_MCAP_REM		_BITUL(0)
> > >  #define MPTCP_SUBFLOW_FLAG_MCAP_LOC		_BITUL(1)
> > > @@ -244,9 +245,24 @@ struct mptcp_subflow_addrs {
> > >  	};
> > >  };
> > >  
> > > +struct mptcp_subflow_info {
> > > +	__u32				id;
> > > +	struct mptcp_subflow_addrs	addrs;
> > > +};
> > > +
> > > +/* struct subflow_info is not supposed nor allowed to grow in
> > > + * future versions.
> > > + * If need will arise, a new socket option should be added.
> > > + */
> > > +struct mptcp_subflow_full_info {
> > > +	struct mptcp_subflow_info	subflow_info;
> > > +	struct tcp_info			tcp_info;
> > > +};
> > 
> > I dislike this constraint.
> > 
> > Why not do something like this:
> > 
> > struct mptcp_subflow_full_info {
> > 	__u32		size_subflow_full_info;         /* size of this structure in userspace */
> > 	__u32           num_subflows_user;              /* max subflows that userspace is interested in */
> > 	__u32           num_subflows_kern;              /* must be 0, set by kernel (real subflow count) */
> > 	__u32		num_subflows_copied;		/* must be 0, set by kernel (number of subflow infos copied back)
> >         __u32           size_sfinfo_kernel;		/* must be 0, set by kernel */
> >         __u32           size_sfinfo_user;
> >         __u32           size_tcpinfo_kernel;            /* must be 0, set by kernel */
> >         __u32           size_tcpinfo_user;
> > 	__aligned_u64	subflow_info_addr;
> > 	__aligned_u64	tcp_info_addr;
> > };
> > 
> > userspace does:
> > 
> > x = calloc(sizeof(struct mptcp_subflow_info), 42);
> > y = calloc(sizeof(struct tcp_info), 42);
> > 
> > struct mptcp_subflow_full_info {
> > 	.size_subflow_full_info = sizeof(struct mptcp_subflow_full_info),
> > 	.num_subflows_user = 42,
> > 	.size_sfinfo_user = sizeof(struct mptcp_subflow_info),
> > 	.size_tcpinfo_user = sizeof(struct mptcp_subflow_info),
> > 	.subflow_info_addr = (u64)x,
> > 	.tcp_info_addr = (u64)y,
> > };
> > 
> > kernel does:
> > 1. put_user() the real sizes uses by the kernel
> > 2. put_user() the real subflow count
> > 3. copy subflow_info_addr and tcp_info_addr addresses
> > 4. treat as userspace pointers
> > 
> > for each subflow, copy tcpinfo and subflow info to the
> > two arrays provided by userspace.
> > 
> > Kernel truncates copied data via size_sfinfo_user/size_tcpinfo_user so
> > that new kernel won't populate fields that don't exist in userspace.
> > 
> > Kernel stops copying after 'num_subflows_user' or 'num_subflows_kern',
> > whatever comes first and updates num_subflows_copied to the real copied
> > value.
> > 
> > This allows userspace to discover when kernel had more subflows
> > but could not place the data due to lack of space in the
> > userspace-provided arrays.
> > 
> > This is more complicated but no need to add new MPTCP_FULL_INFO_V2/V3/V4
> > etc. in the future.
> > 
> > What do you think?
> 
> I ended-up with the current code trying to re-use as much as possible
> from the existing infra - specifically the
> mptcp_get_subflow_data()/mptcp_put_subflow_data() helpers.
> 
> I agree the constraint on mptcp_subflow_full_info is not nice,
> especially if we want to include subflow level indormation alike
> local/remote address id, flags, etc...
> 
> Isn't num_subflows_copied always implied? == min(num_subflows_user,
> num_subflows_kern).
> 
> Otherwise LGTM, I'll try to have a spin.

Oops, I forgot... should mptcp_subflow_full_info contain mptcp_info,
too? Overall layout:

struct mptcp_subflow_full_info {
	__u32		size_subflow_full_info;         /* size of this structure in userspace */
	__u32           num_subflows_user;              /* max subflows that userspace is interested in */
	__u32           num_subflows_kern;              /* must be 0, set by kernel (real subflow count) */
        __u32           size_sfinfo_kernel;		/* must be 0, set by kernel */
        __u32           size_sfinfo_user;
        __u32           size_tcpinfo_kernel;            /* must be 0, set by kernel */
        __u32           size_tcpinfo_user;
	__aligned_u64	subflow_info_addr;
	__aligned_u64	tcp_info_addr;
	struct mptcp_info mptcp_indo;
};
Re: [PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Matthieu Baerts 1 year, 3 months ago
Hi Paolo, Florian,

On 24/05/2023 08:36, Paolo Abeni wrote:
> On Wed, 2023-05-24 at 08:34 +0200, Paolo Abeni wrote:
>> On Tue, 2023-05-23 at 20:25 +0200, Florian Westphal wrote:
>>> Paolo Abeni <pabeni@redhat.com> wrote:
>>>> Some user-space applications want to monitor the subflows utilization.
>>>>
>>>> Dumping the per subflow tcp_info is not enough, as the PM could close
>>>> and re-create the subflows under-the-hood, fooling the accounting.
>>>> Even checking the src/dst addresses used by each subflow could not
>>>> be enough, because new subflows could re-use the same address/port of
>>>> the just closed one.
>>>>
>>>> This patch introduces a new socket option, allow dumping all the relevant
>>>> information all-at-once (everything, everywhere...), in a consistent manner.
>>>>
>>>> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
>>>> ---
>>>> v2 -> v3:
>>>>  - added missing changelog (oops)
>>>> ---
>>>>  include/uapi/linux/mptcp.h | 16 ++++++++
>>>>  net/mptcp/sockopt.c        | 75 ++++++++++++++++++++++++++++++++++++++
>>>>  2 files changed, 91 insertions(+)
>>>>
>>>> diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h
>>>> index 32af2d278cb4..f4f42d88e58b 100644
>>>> --- a/include/uapi/linux/mptcp.h
>>>> +++ b/include/uapi/linux/mptcp.h
>>>> @@ -12,6 +12,7 @@
>>>>  #include <linux/in.h>		/* for sockaddr_in			*/
>>>>  #include <linux/in6.h>		/* for sockaddr_in6			*/
>>>>  #include <linux/socket.h>	/* for sockaddr_storage and sa_family	*/
>>>> +#include <linux/tcp.h>		/* for tcp_info				*/
>>>>  
>>>>  #define MPTCP_SUBFLOW_FLAG_MCAP_REM		_BITUL(0)
>>>>  #define MPTCP_SUBFLOW_FLAG_MCAP_LOC		_BITUL(1)
>>>> @@ -244,9 +245,24 @@ struct mptcp_subflow_addrs {
>>>>  	};
>>>>  };
>>>>  
>>>> +struct mptcp_subflow_info {
>>>> +	__u32				id;
>>>> +	struct mptcp_subflow_addrs	addrs;
>>>> +};
>>>> +
>>>> +/* struct subflow_info is not supposed nor allowed to grow in
>>>> + * future versions.
>>>> + * If need will arise, a new socket option should be added.
>>>> + */
>>>> +struct mptcp_subflow_full_info {
>>>> +	struct mptcp_subflow_info	subflow_info;
>>>> +	struct tcp_info			tcp_info;
>>>> +};
>>>
>>> I dislike this constraint.
>>>
>>> Why not do something like this:
>>>
>>> struct mptcp_subflow_full_info {
>>> 	__u32		size_subflow_full_info;         /* size of this structure in userspace */
>>> 	__u32           num_subflows_user;              /* max subflows that userspace is interested in */
>>> 	__u32           num_subflows_kern;              /* must be 0, set by kernel (real subflow count) */
>>> 	__u32		num_subflows_copied;		/* must be 0, set by kernel (number of subflow infos copied back)
>>>         __u32           size_sfinfo_kernel;		/* must be 0, set by kernel */
>>>         __u32           size_sfinfo_user;
>>>         __u32           size_tcpinfo_kernel;            /* must be 0, set by kernel */
>>>         __u32           size_tcpinfo_user;
>>> 	__aligned_u64	subflow_info_addr;
>>> 	__aligned_u64	tcp_info_addr;
>>> };
>>>
>>> userspace does:
>>>
>>> x = calloc(sizeof(struct mptcp_subflow_info), 42);
>>> y = calloc(sizeof(struct tcp_info), 42);
>>>
>>> struct mptcp_subflow_full_info {
>>> 	.size_subflow_full_info = sizeof(struct mptcp_subflow_full_info),
>>> 	.num_subflows_user = 42,
>>> 	.size_sfinfo_user = sizeof(struct mptcp_subflow_info),
>>> 	.size_tcpinfo_user = sizeof(struct mptcp_subflow_info),
>>> 	.subflow_info_addr = (u64)x,
>>> 	.tcp_info_addr = (u64)y,
>>> };
>>>
>>> kernel does:
>>> 1. put_user() the real sizes uses by the kernel
>>> 2. put_user() the real subflow count
>>> 3. copy subflow_info_addr and tcp_info_addr addresses
>>> 4. treat as userspace pointers
>>>
>>> for each subflow, copy tcpinfo and subflow info to the
>>> two arrays provided by userspace.
>>>
>>> Kernel truncates copied data via size_sfinfo_user/size_tcpinfo_user so
>>> that new kernel won't populate fields that don't exist in userspace.
>>>
>>> Kernel stops copying after 'num_subflows_user' or 'num_subflows_kern',
>>> whatever comes first and updates num_subflows_copied to the real copied
>>> value.
>>>
>>> This allows userspace to discover when kernel had more subflows
>>> but could not place the data due to lack of space in the
>>> userspace-provided arrays.
>>>
>>> This is more complicated but no need to add new MPTCP_FULL_INFO_V2/V3/V4
>>> etc. in the future.
>>>
>>> What do you think?
>>
>> I ended-up with the current code trying to re-use as much as possible
>> from the existing infra - specifically the
>> mptcp_get_subflow_data()/mptcp_put_subflow_data() helpers.
>>
>> I agree the constraint on mptcp_subflow_full_info is not nice,
>> especially if we want to include subflow level indormation alike
>> local/remote address id, flags, etc...
>>
>> Isn't num_subflows_copied always implied? == min(num_subflows_user,
>> num_subflows_kern).
>>
>> Otherwise LGTM, I'll try to have a spin.
> 
> Oops, I forgot... should mptcp_subflow_full_info contain mptcp_info,
> too?

Good point. Indeed I guess it is very likely someone who want info about
MPTCP subflow will also want info about the MPTCP connection.

> Overall layout:
> 
> struct mptcp_subflow_full_info {
> 	__u32		size_subflow_full_info;         /* size of this structure in userspace */
> 	__u32           num_subflows_user;              /* max subflows that userspace is interested in */
> 	__u32           num_subflows_kern;              /* must be 0, set by kernel (real subflow count) */
>         __u32           size_sfinfo_kernel;		/* must be 0, set by kernel */
>         __u32           size_sfinfo_user;
>         __u32           size_tcpinfo_kernel;            /* must be 0, set by kernel */
>         __u32           size_tcpinfo_user;
> 	__aligned_u64	subflow_info_addr;
> 	__aligned_u64	tcp_info_addr;
> 	struct mptcp_info mptcp_indo;

I guess you will need a size for the mptcp_info structure, no?

Maybe this should come before the previous ones?

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
Re: [PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Paolo Abeni 1 year, 3 months ago
On Wed, 2023-05-24 at 09:36 +0200, Matthieu Baerts wrote:
> Hi Paolo, Florian,
> 
> On 24/05/2023 08:36, Paolo Abeni wrote:
> > On Wed, 2023-05-24 at 08:34 +0200, Paolo Abeni wrote:
> > > On Tue, 2023-05-23 at 20:25 +0200, Florian Westphal wrote:
> > > > Paolo Abeni <pabeni@redhat.com> wrote:
> > > > > Some user-space applications want to monitor the subflows utilization.
> > > > > 
> > > > > Dumping the per subflow tcp_info is not enough, as the PM could close
> > > > > and re-create the subflows under-the-hood, fooling the accounting.
> > > > > Even checking the src/dst addresses used by each subflow could not
> > > > > be enough, because new subflows could re-use the same address/port of
> > > > > the just closed one.
> > > > > 
> > > > > This patch introduces a new socket option, allow dumping all the relevant
> > > > > information all-at-once (everything, everywhere...), in a consistent manner.
> > > > > 
> > > > > Signed-off-by: Paolo Abeni <pabeni@redhat.com>
> > > > > ---
> > > > > v2 -> v3:
> > > > >  - added missing changelog (oops)
> > > > > ---
> > > > >  include/uapi/linux/mptcp.h | 16 ++++++++
> > > > >  net/mptcp/sockopt.c        | 75 ++++++++++++++++++++++++++++++++++++++
> > > > >  2 files changed, 91 insertions(+)
> > > > > 
> > > > > diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h
> > > > > index 32af2d278cb4..f4f42d88e58b 100644
> > > > > --- a/include/uapi/linux/mptcp.h
> > > > > +++ b/include/uapi/linux/mptcp.h
> > > > > @@ -12,6 +12,7 @@
> > > > >  #include <linux/in.h>		/* for sockaddr_in			*/
> > > > >  #include <linux/in6.h>		/* for sockaddr_in6			*/
> > > > >  #include <linux/socket.h>	/* for sockaddr_storage and sa_family	*/
> > > > > +#include <linux/tcp.h>		/* for tcp_info				*/
> > > > >  
> > > > >  #define MPTCP_SUBFLOW_FLAG_MCAP_REM		_BITUL(0)
> > > > >  #define MPTCP_SUBFLOW_FLAG_MCAP_LOC		_BITUL(1)
> > > > > @@ -244,9 +245,24 @@ struct mptcp_subflow_addrs {
> > > > >  	};
> > > > >  };
> > > > >  
> > > > > +struct mptcp_subflow_info {
> > > > > +	__u32				id;
> > > > > +	struct mptcp_subflow_addrs	addrs;
> > > > > +};
> > > > > +
> > > > > +/* struct subflow_info is not supposed nor allowed to grow in
> > > > > + * future versions.
> > > > > + * If need will arise, a new socket option should be added.
> > > > > + */
> > > > > +struct mptcp_subflow_full_info {
> > > > > +	struct mptcp_subflow_info	subflow_info;
> > > > > +	struct tcp_info			tcp_info;
> > > > > +};
> > > > 
> > > > I dislike this constraint.
> > > > 
> > > > Why not do something like this:
> > > > 
> > > > struct mptcp_subflow_full_info {
> > > > 	__u32		size_subflow_full_info;         /* size of this structure in userspace */
> > > > 	__u32           num_subflows_user;              /* max subflows that userspace is interested in */
> > > > 	__u32           num_subflows_kern;              /* must be 0, set by kernel (real subflow count) */
> > > > 	__u32		num_subflows_copied;		/* must be 0, set by kernel (number of subflow infos copied back)
> > > >         __u32           size_sfinfo_kernel;		/* must be 0, set by kernel */
> > > >         __u32           size_sfinfo_user;
> > > >         __u32           size_tcpinfo_kernel;            /* must be 0, set by kernel */
> > > >         __u32           size_tcpinfo_user;
> > > > 	__aligned_u64	subflow_info_addr;
> > > > 	__aligned_u64	tcp_info_addr;
> > > > };
> > > > 
> > > > userspace does:
> > > > 
> > > > x = calloc(sizeof(struct mptcp_subflow_info), 42);
> > > > y = calloc(sizeof(struct tcp_info), 42);
> > > > 
> > > > struct mptcp_subflow_full_info {
> > > > 	.size_subflow_full_info = sizeof(struct mptcp_subflow_full_info),
> > > > 	.num_subflows_user = 42,
> > > > 	.size_sfinfo_user = sizeof(struct mptcp_subflow_info),
> > > > 	.size_tcpinfo_user = sizeof(struct mptcp_subflow_info),
> > > > 	.subflow_info_addr = (u64)x,
> > > > 	.tcp_info_addr = (u64)y,
> > > > };
> > > > 
> > > > kernel does:
> > > > 1. put_user() the real sizes uses by the kernel
> > > > 2. put_user() the real subflow count
> > > > 3. copy subflow_info_addr and tcp_info_addr addresses
> > > > 4. treat as userspace pointers
> > > > 
> > > > for each subflow, copy tcpinfo and subflow info to the
> > > > two arrays provided by userspace.
> > > > 
> > > > Kernel truncates copied data via size_sfinfo_user/size_tcpinfo_user so
> > > > that new kernel won't populate fields that don't exist in userspace.
> > > > 
> > > > Kernel stops copying after 'num_subflows_user' or 'num_subflows_kern',
> > > > whatever comes first and updates num_subflows_copied to the real copied
> > > > value.
> > > > 
> > > > This allows userspace to discover when kernel had more subflows
> > > > but could not place the data due to lack of space in the
> > > > userspace-provided arrays.
> > > > 
> > > > This is more complicated but no need to add new MPTCP_FULL_INFO_V2/V3/V4
> > > > etc. in the future.
> > > > 
> > > > What do you think?
> > > 
> > > I ended-up with the current code trying to re-use as much as possible
> > > from the existing infra - specifically the
> > > mptcp_get_subflow_data()/mptcp_put_subflow_data() helpers.
> > > 
> > > I agree the constraint on mptcp_subflow_full_info is not nice,
> > > especially if we want to include subflow level indormation alike
> > > local/remote address id, flags, etc...
> > > 
> > > Isn't num_subflows_copied always implied? == min(num_subflows_user,
> > > num_subflows_kern).
> > > 
> > > Otherwise LGTM, I'll try to have a spin.
> > 
> > Oops, I forgot... should mptcp_subflow_full_info contain mptcp_info,
> > too?
> 
> Good point. Indeed I guess it is very likely someone who want info about
> MPTCP subflow will also want info about the MPTCP connection.
> 
> > Overall layout:
> > 
> > struct mptcp_subflow_full_info {
> > 	__u32		size_subflow_full_info;         /* size of this structure in userspace */
> > 	__u32           num_subflows_user;              /* max subflows that userspace is interested in */
> > 	__u32           num_subflows_kern;              /* must be 0, set by kernel (real subflow count) */
> >         __u32           size_sfinfo_kernel;		/* must be 0, set by kernel */
> >         __u32           size_sfinfo_user;
> >         __u32           size_tcpinfo_kernel;            /* must be 0, set by kernel */
> >         __u32           size_tcpinfo_user;
> > 	__aligned_u64	subflow_info_addr;
> > 	__aligned_u64	tcp_info_addr;
> > 	struct mptcp_info mptcp_indo;
> 
> I guess you will need a size for the mptcp_info structure, no?
> 
> Maybe this should come before the previous ones?

I'm coding the thing right now: it turns out we are better of not
including mptcp_info inside mptcp_subflow_full_info, so the
manipulation schema will look alike the exiting
mptcp_{get,put}_subflow_data().

Also the user mptcp_info size is implied, since is always equal to  
*optlen - mptcp_subflow_full_info.mptcp_subflow_full_info. 

/P
Re: [PATCH v3 mptcp-next 2/6] mptcp: introduce MPTCP_FULL_INFO getsockopt
Posted by Matthieu Baerts 1 year, 3 months ago
Hi Paolo,

On 24/05/2023 10:11, Paolo Abeni wrote:
> On Wed, 2023-05-24 at 09:36 +0200, Matthieu Baerts wrote:
>> Hi Paolo, Florian,
>>
>> On 24/05/2023 08:36, Paolo Abeni wrote:
>>> On Wed, 2023-05-24 at 08:34 +0200, Paolo Abeni wrote:
>>>> On Tue, 2023-05-23 at 20:25 +0200, Florian Westphal wrote:
>>>>> Paolo Abeni <pabeni@redhat.com> wrote:
>>>>>> Some user-space applications want to monitor the subflows utilization.
>>>>>>
>>>>>> Dumping the per subflow tcp_info is not enough, as the PM could close
>>>>>> and re-create the subflows under-the-hood, fooling the accounting.
>>>>>> Even checking the src/dst addresses used by each subflow could not
>>>>>> be enough, because new subflows could re-use the same address/port of
>>>>>> the just closed one.
>>>>>>
>>>>>> This patch introduces a new socket option, allow dumping all the relevant
>>>>>> information all-at-once (everything, everywhere...), in a consistent manner.
>>>>>>
>>>>>> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
>>>>>> ---
>>>>>> v2 -> v3:
>>>>>>  - added missing changelog (oops)
>>>>>> ---
>>>>>>  include/uapi/linux/mptcp.h | 16 ++++++++
>>>>>>  net/mptcp/sockopt.c        | 75 ++++++++++++++++++++++++++++++++++++++
>>>>>>  2 files changed, 91 insertions(+)
>>>>>>
>>>>>> diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h
>>>>>> index 32af2d278cb4..f4f42d88e58b 100644
>>>>>> --- a/include/uapi/linux/mptcp.h
>>>>>> +++ b/include/uapi/linux/mptcp.h
>>>>>> @@ -12,6 +12,7 @@
>>>>>>  #include <linux/in.h>		/* for sockaddr_in			*/
>>>>>>  #include <linux/in6.h>		/* for sockaddr_in6			*/
>>>>>>  #include <linux/socket.h>	/* for sockaddr_storage and sa_family	*/
>>>>>> +#include <linux/tcp.h>		/* for tcp_info				*/
>>>>>>  
>>>>>>  #define MPTCP_SUBFLOW_FLAG_MCAP_REM		_BITUL(0)
>>>>>>  #define MPTCP_SUBFLOW_FLAG_MCAP_LOC		_BITUL(1)
>>>>>> @@ -244,9 +245,24 @@ struct mptcp_subflow_addrs {
>>>>>>  	};
>>>>>>  };
>>>>>>  
>>>>>> +struct mptcp_subflow_info {
>>>>>> +	__u32				id;
>>>>>> +	struct mptcp_subflow_addrs	addrs;
>>>>>> +};
>>>>>> +
>>>>>> +/* struct subflow_info is not supposed nor allowed to grow in
>>>>>> + * future versions.
>>>>>> + * If need will arise, a new socket option should be added.
>>>>>> + */
>>>>>> +struct mptcp_subflow_full_info {
>>>>>> +	struct mptcp_subflow_info	subflow_info;
>>>>>> +	struct tcp_info			tcp_info;
>>>>>> +};
>>>>>
>>>>> I dislike this constraint.
>>>>>
>>>>> Why not do something like this:
>>>>>
>>>>> struct mptcp_subflow_full_info {
>>>>> 	__u32		size_subflow_full_info;         /* size of this structure in userspace */
>>>>> 	__u32           num_subflows_user;              /* max subflows that userspace is interested in */
>>>>> 	__u32           num_subflows_kern;              /* must be 0, set by kernel (real subflow count) */
>>>>> 	__u32		num_subflows_copied;		/* must be 0, set by kernel (number of subflow infos copied back)
>>>>>         __u32           size_sfinfo_kernel;		/* must be 0, set by kernel */
>>>>>         __u32           size_sfinfo_user;
>>>>>         __u32           size_tcpinfo_kernel;            /* must be 0, set by kernel */
>>>>>         __u32           size_tcpinfo_user;
>>>>> 	__aligned_u64	subflow_info_addr;
>>>>> 	__aligned_u64	tcp_info_addr;
>>>>> };
>>>>>
>>>>> userspace does:
>>>>>
>>>>> x = calloc(sizeof(struct mptcp_subflow_info), 42);
>>>>> y = calloc(sizeof(struct tcp_info), 42);
>>>>>
>>>>> struct mptcp_subflow_full_info {
>>>>> 	.size_subflow_full_info = sizeof(struct mptcp_subflow_full_info),
>>>>> 	.num_subflows_user = 42,
>>>>> 	.size_sfinfo_user = sizeof(struct mptcp_subflow_info),
>>>>> 	.size_tcpinfo_user = sizeof(struct mptcp_subflow_info),
>>>>> 	.subflow_info_addr = (u64)x,
>>>>> 	.tcp_info_addr = (u64)y,
>>>>> };
>>>>>
>>>>> kernel does:
>>>>> 1. put_user() the real sizes uses by the kernel
>>>>> 2. put_user() the real subflow count
>>>>> 3. copy subflow_info_addr and tcp_info_addr addresses
>>>>> 4. treat as userspace pointers
>>>>>
>>>>> for each subflow, copy tcpinfo and subflow info to the
>>>>> two arrays provided by userspace.
>>>>>
>>>>> Kernel truncates copied data via size_sfinfo_user/size_tcpinfo_user so
>>>>> that new kernel won't populate fields that don't exist in userspace.
>>>>>
>>>>> Kernel stops copying after 'num_subflows_user' or 'num_subflows_kern',
>>>>> whatever comes first and updates num_subflows_copied to the real copied
>>>>> value.
>>>>>
>>>>> This allows userspace to discover when kernel had more subflows
>>>>> but could not place the data due to lack of space in the
>>>>> userspace-provided arrays.
>>>>>
>>>>> This is more complicated but no need to add new MPTCP_FULL_INFO_V2/V3/V4
>>>>> etc. in the future.
>>>>>
>>>>> What do you think?
>>>>
>>>> I ended-up with the current code trying to re-use as much as possible
>>>> from the existing infra - specifically the
>>>> mptcp_get_subflow_data()/mptcp_put_subflow_data() helpers.
>>>>
>>>> I agree the constraint on mptcp_subflow_full_info is not nice,
>>>> especially if we want to include subflow level indormation alike
>>>> local/remote address id, flags, etc...
>>>>
>>>> Isn't num_subflows_copied always implied? == min(num_subflows_user,
>>>> num_subflows_kern).
>>>>
>>>> Otherwise LGTM, I'll try to have a spin.
>>>
>>> Oops, I forgot... should mptcp_subflow_full_info contain mptcp_info,
>>> too?
>>
>> Good point. Indeed I guess it is very likely someone who want info about
>> MPTCP subflow will also want info about the MPTCP connection.
>>
>>> Overall layout:
>>>
>>> struct mptcp_subflow_full_info {
>>> 	__u32		size_subflow_full_info;         /* size of this structure in userspace */
>>> 	__u32           num_subflows_user;              /* max subflows that userspace is interested in */
>>> 	__u32           num_subflows_kern;              /* must be 0, set by kernel (real subflow count) */
>>>         __u32           size_sfinfo_kernel;		/* must be 0, set by kernel */
>>>         __u32           size_sfinfo_user;
>>>         __u32           size_tcpinfo_kernel;            /* must be 0, set by kernel */
>>>         __u32           size_tcpinfo_user;
>>> 	__aligned_u64	subflow_info_addr;
>>> 	__aligned_u64	tcp_info_addr;
>>> 	struct mptcp_info mptcp_indo;
>>
>> I guess you will need a size for the mptcp_info structure, no?
>>
>> Maybe this should come before the previous ones?
> 
> I'm coding the thing right now: it turns out we are better of not
> including mptcp_info inside mptcp_subflow_full_info, so the
> manipulation schema will look alike the exiting
> mptcp_{get,put}_subflow_data().

(if you are coding this right now, and also linked to my previous email,
we can also continue the discussion on IRC if it is easier for you :) )

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net