Skip to contentSkip to conversation

BPF path manager, part 4

PATCH Superseded Geliang Tang 3 participants 8 messages Jan 16, 2025 – Feb 14, 2025

Subsystems (2)

v3 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v3 cover BPF path manager, part 4

From: Geliang Tang <[email protected]>

v3:
- rename the 2nd parameter of get_local_id() from 'local' to 'skc'.
- keep the 'msk_sport' check in mptcp_userspace_pm_get_local_id().
- return 'err' instead of '0' in userspace_pm_subflow_create().
- drop 'ret' variable inmptcp_pm_data_reset().
- fix typos in commit log.

Depends on: "BPF path manager, part 3" v4
Based-on: <[email protected]>

v2:
- update get_local_id interface in patch 2.

get_addr() and dump_addr() interfaces of BPF userspace pm are dropped as Matt suggested.

In order to implement BPF userspace path manager, it is necessary to unify the interfaces of the path manager. This set contains some cleanups and refactoring to unify the interfaces in kernel space. Finally, define a struct mptcp_pm_ops for a userspace path manager like this:

struct mptcp_pm_ops {
	int (*address_announce)(struct mptcp_sock *msk,
				struct mptcp_pm_addr_entry *local);
	int (*address_remove)(struct mptcp_sock *msk, u8 id);
	int (*subflow_create)(struct mptcp_sock *msk,
			      struct mptcp_pm_addr_entry *local,
			      struct mptcp_addr_info *remote);
	int (*subflow_destroy)(struct mptcp_sock *msk,
			       struct mptcp_pm_addr_entry *local,
			       struct mptcp_addr_info *remote);
	int (*get_local_id)(struct mptcp_sock *msk,
			    struct mptcp_pm_addr_entry *skc);
	u8 (*get_flags)(struct mptcp_sock *msk,
			struct mptcp_addr_info *skc);
	int (*set_flags)(struct mptcp_sock *msk,
			 struct mptcp_pm_addr_entry *local,
			 struct mptcp_addr_info *remote);

	u8			type;
	struct module		*owner;
	struct list_head	list;

	void (*init)(struct mptcp_sock *msk);
	void (*release)(struct mptcp_sock *msk);
} ____cacheline_aligned_in_smp;

Geliang Tang (3):
mptcp: define struct mptcp_pm_ops
mptcp: register default userspace pm
mptcp: init and release mptcp_pm_ops

 include/net/mptcp.h      |  27 +++
 net/mptcp/pm.c           |   5 +
 net/mptcp/pm_userspace.c | 374 ++++++++++++++++++++++++++++-----------
 net/mptcp/protocol.c     |   1 +
 net/mptcp/protocol.h     |   9 +
 5 files changed, 313 insertions(+), 103 deletions(-)
Signature · 1 line
2.43.0
author reviewer
#1 lore raw

PATCH v3 1/3 mptcp: define struct mptcp_pm_ops

From: Geliang Tang <[email protected]>

In order to allow users to develop their own BPF-based path manager, this patch defines a struct ops "mptcp_pm_ops" for a userspace path manager, which contains a set of interfaces.

Add a set of functions to register, unregister, find and validate a given struct ops.

---
 include/net/mptcp.h      | 27 +++++++++++++++++++
 net/mptcp/pm_userspace.c | 57 ++++++++++++++++++++++++++++++++++++++++
 net/mptcp/protocol.h     |  5 ++++
 3 files changed, 89 insertions(+)
include/net/mptcp.h +27 -0
index 94d5976f7b8d..8829632289da 100644
@@ -14,6 +14,7 @@
 
 struct mptcp_info;
 struct mptcp_sock;
+struct mptcp_pm_addr_entry;
 struct seq_file;
 
 /* MPTCP sk_buff extension data */
@@ -120,6 +121,32 @@ struct mptcp_sched_ops {
 	void (*release)(struct mptcp_sock *msk);
 } ____cacheline_aligned_in_smp;
 
+struct mptcp_pm_ops {
+	int (*address_announce)(struct mptcp_sock *msk,
+				struct mptcp_pm_addr_entry *local);
+	int (*address_remove)(struct mptcp_sock *msk, u8 id);
+	int (*subflow_create)(struct mptcp_sock *msk,
+			      struct mptcp_pm_addr_entry *local,
+			      struct mptcp_addr_info *remote);
+	int (*subflow_destroy)(struct mptcp_sock *msk,
+			       struct mptcp_pm_addr_entry *local,
+			       struct mptcp_addr_info *remote);
+	int (*get_local_id)(struct mptcp_sock *msk,
+			    struct mptcp_pm_addr_entry *skc);
+	u8 (*get_flags)(struct mptcp_sock *msk,
+			struct mptcp_addr_info *skc);
+	int (*set_flags)(struct mptcp_sock *msk,
+			 struct mptcp_pm_addr_entry *local,
+			 struct mptcp_addr_info *remote);
+
+	u8			type;
+	struct module		*owner;
+	struct list_head	list;
+
+	void (*init)(struct mptcp_sock *msk);
+	void (*release)(struct mptcp_sock *msk);
+} ____cacheline_aligned_in_smp;
+
 #ifdef CONFIG_MPTCP
 void mptcp_init(void);
 
net/mptcp/pm_userspace.c +57 -0

72 lines not on this page · raw message

net/mptcp/protocol.h +5 -0
index 821d9d51e27c..1a0718fade23 100644
@@ -1048,6 +1048,11 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_
 void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk,
 				struct mptcp_pm_addr_entry *entry);
 
+struct mptcp_pm_ops *mptcp_pm_find(enum mptcp_pm_type type);
+int mptcp_validate_path_manager(struct mptcp_pm_ops *pm);
+int mptcp_register_path_manager(struct mptcp_pm_ops *pm);
+void mptcp_unregister_path_manager(struct mptcp_pm_ops *pm);
+
 void mptcp_free_local_addr_list(struct mptcp_sock *msk);
 
 void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
Signature · 1 line
2.43.0
author reviewer
#2 lore raw

PATCH v3 2/3 mptcp: register default userspace pm

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

This patch defines the original userspace pm as the default path manager, named mptcp_userspace_pm, and register it in mptcp_pm_data_init().

Extract address_announce() interface of the userspace PM from the handler of netlink command MPTCP_PM_CMD_ANNOUNCE mptcp_pm_nl_announce_doit(), only leave the code for obtaining msk through "info" and parsing address entry in the handler.

Extract address_remove() interface of the userspace PM from the handler of netlink command MPTCP_PM_CMD_REMOVE mptcp_pm_nl_remove_doit(), only leave the code for parsing address id and obtaining msk through "info" in the handler.

Extract subflow_create() interface of the userspace PM from the handler of netlink command MPTCP_PM_CMD_SUBFLOW_CREATE

mptcp_pm_nl_subflow_create_doit(),

only leave the code for obtaining msk through "info", parsing local address entry and parsing remote address info in the handler.

Extract subflow_destroy() interface of the userspace PM from the handler of netlink command MPTCP_PM_CMD_SUBFLOW_DESTROY

mptcp_pm_nl_subflow_destroy_doit(),

only leave the code for obtaining msk through "info", parsing local address entry and parsing remote address info in the handler.

Extract set_flags() interface of the userspace PM from function mptcp_userspace_pm_set_flags(), only leave the code for obtaining msk through "info" in this function.

All fives interfaces are invoked under holding the msk socket lock.

Extract get_local_id() interface of the userspace PM from function mptcp_userspace_pm_get_local_id(), only leave the code for setting new address entry in this function.

get_flags() interface of the userspace PM is defined as the same as the function mptcp_userspace_pm_get_flags(), then this function becomes a wrapper.

---
 net/mptcp/pm.c           |   1 +
 net/mptcp/pm_userspace.c | 273 ++++++++++++++++++++++++---------------
 net/mptcp/protocol.h     |   1 +
 3 files changed, 172 insertions(+), 103 deletions(-)
net/mptcp/pm.c +1 -0
index e275be73b963..3b47c2380a44 100644
@@ -646,4 +646,5 @@ void mptcp_pm_data_init(struct mptcp_sock *msk)
 void __init mptcp_pm_init(void)
 {
 	mptcp_pm_nl_init();
+	mptcp_userspace_pm_init();
 }
net/mptcp/pm_userspace.c +170 -103

407 lines not on this page · raw message

net/mptcp/protocol.h +1 -0
index 1a0718fade23..6034190e0d78 100644
@@ -1158,6 +1158,7 @@ static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflo
 }
 
 void __init mptcp_pm_nl_init(void);
+void __init mptcp_userspace_pm_init(void);
 void mptcp_pm_nl_work(struct mptcp_sock *msk);
 unsigned int mptcp_pm_get_add_addr_signal_max(const struct mptcp_sock *msk);
 unsigned int mptcp_pm_get_add_addr_accept_max(const struct mptcp_sock *msk);
Signature · 1 line
2.43.0
author reviewer
#3 lore raw

PATCH v3 3/3 mptcp: init and release mptcp_pm_ops

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Add a struct mptcp_pm_ops pointer "ops" in struct mptcp_pm_data, and two functions mptcp_init_pm() and mptcp_release_pm(), to set and release this pointer. mptcp_init_pm() is invoked in mptcp_pm_data_reset(), while mptcp_release_pm() is invoked in __mptcp_destroy_sock().

In this way, different userspace path managers can be initialized through the pm_type sysctl, and then called into their respective interfaces through "ops" of "msk->pm".

---
 net/mptcp/pm.c           |  4 +++
 net/mptcp/pm_userspace.c | 58 +++++++++++++++++++++++++++++++++++-----
 net/mptcp/protocol.c     |  1 +
 net/mptcp/protocol.h     |  3 +++
 4 files changed, 59 insertions(+), 7 deletions(-)
net/mptcp/pm.c +4 -0
index 3b47c2380a44..75faa0a909d7 100644
@@ -627,6 +627,10 @@ void mptcp_pm_data_reset(struct mptcp_sock *msk)
 		WRITE_ONCE(pm->work_pending, 0);
 		WRITE_ONCE(pm->accept_addr, 0);
 		WRITE_ONCE(pm->accept_subflow, 0);
+
+		rcu_read_lock();
+		mptcp_init_pm(msk, mptcp_pm_find(pm_type));
+		rcu_read_unlock();
 	}
 
 	WRITE_ONCE(pm->addr_signal, 0);
net/mptcp/pm_userspace.c +51 -7

106 lines not on this page · raw message

net/mptcp/protocol.c +1 -0
index 5cda189d29f2..bba22c3f7279 100644
@@ -2940,6 +2940,7 @@ static void __mptcp_destroy_sock(struct sock *sk)
 	sk_stop_timer(sk, &sk->sk_timer);
 	msk->pm.status = 0;
 	mptcp_release_sched(msk);
+	mptcp_release_pm(msk);
 
 	sk->sk_prot->destroy(sk);
 
net/mptcp/protocol.h +3 -0
index 6034190e0d78..ab57ce556246 100644
@@ -221,6 +221,7 @@ struct mptcp_pm_data {
 	struct mptcp_addr_info remote;
 	struct list_head anno_list;
 	struct list_head userspace_pm_local_addr_list;
+	struct mptcp_pm_ops *ops;
 
 	spinlock_t	lock;		/*protects the whole PM data */
 
@@ -1052,6 +1053,8 @@ struct mptcp_pm_ops *mptcp_pm_find(enum mptcp_pm_type type);
 int mptcp_validate_path_manager(struct mptcp_pm_ops *pm);
 int mptcp_register_path_manager(struct mptcp_pm_ops *pm);
 void mptcp_unregister_path_manager(struct mptcp_pm_ops *pm);
+int mptcp_init_pm(struct mptcp_sock *msk, struct mptcp_pm_ops *pm);
+void mptcp_release_pm(struct mptcp_sock *msk);
 
 void mptcp_free_local_addr_list(struct mptcp_sock *msk);
 
Signature · 1 line
2.43.0
#4 lore raw
In reply to Geliang Tang

Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Unstable: 1 failed test(s): selftest_mptcp_join - Critical: 1 Call Trace(s) ❌
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/12804456330

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/50059925b7f3
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=925962

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

maintainer
#5 lore raw
In reply to Geliang Tang

Hi Geliang,

Quoted 15 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v3:
- rename the 2nd parameter of get_local_id() from 'local' to 'skc'.
- keep the 'msk_sport' check in mptcp_userspace_pm_get_local_id().
- return 'err' instead of '0' in userspace_pm_subflow_create().
- drop 'ret' variable inmptcp_pm_data_reset().
- fix typos in commit log.

Depends on: "BPF path manager, part 3" v4
Based-on: <[email protected]>

v2:
- update get_local_id interface in patch 2.

Quoted 8 lines

get_addr() and dump_addr() interfaces of BPF userspace pm are dropped as Matt suggested.

In order to implement BPF userspace path manager, it is necessary to unify the interfaces of the path manager. This set contains some cleanups and refactoring to unify the interfaces in kernel space. Finally, define a struct mptcp_pm_ops for a userspace path manager like this:

Thank you for this series.

From what I see, when a BPF path-manager is loaded, it will replace the userspace one, right?

It looks a bit confusing to know when the (netlink) userspace PM is used, and when the BPF one is. Why not defining a new type instead? Similar to what we have with the packet scheduler? net.mptcp.pm_type could be extended to select a BPF one of a certain ID, no? (or a new type for BPF, then another sysctl to select the name?)

Why not, instead, and similar to the scheduler, have a proper path-manager interface?

For the moment, when the core gets something that might interest the PM, it will directly call a PM helper, then the right PM is picked thanks to mptcp_pm_is_userspace() or mptcp_pm_is_kernel(). That starts to get a bit messy when we want to add more PMs. Instead, the core could simply use the new ops structure, using a pointer stored in the msk.

In other words, when the core needs to notify the PM, it will simply call (directly, or via the PM worker): msk->pm.ops->something_happened() (or via helpers in pm.c that could check if the callback is set, and call mptcp_event() for example)

That way, we have a clear separation of all the different PMs, and the interface is clear to understand the interactions between the core and the PMs.

WDYT?

I hope this doesn't change all your plans. But I think having such interface would help for the maintenance in general.

Quoted 10 lines

struct mptcp_pm_ops {
int (*address_announce)(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *local);
int (*address_remove)(struct mptcp_sock *msk, u8 id); int (*subflow_create)(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *local, struct mptcp_addr_info *remote);
int (*subflow_destroy)(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *local, struct mptcp_addr_info *remote);

Small detail: I would add a 'd' at the end to clearly understand it is linked to an event, not an action, e.g. a new address has just been announced, here is a notification for the PM. So:

address_announced
address_removed
subflow_created
subflow_destroyed

Quoted 7 lines

int (*get_local_id)(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *skc);
u8 (*get_flags)(struct mptcp_sock *msk,
struct mptcp_addr_info *skc);
int (*set_flags)(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *local, struct mptcp_addr_info *remote);

I think it should only be get_priority and set_priority (i.e. backup):
the core doesn't need to know the other (internal) flags.

Also, when looking at mptcp_event_type, I think some events are missing here for a PM to handle the different cases:

created: a new MPTCP has been created, to init some stuff
established: fully established connection, the PM can trigger actions
closed: to free some stuff

And probably 'listerner_created' and 'listener_closed' too.

One last thing; I guess the current 'subflow_created' is more a 'subflow_established', no?
And 'subflow_destroyed' could be 'subflow_closed' to keep the same name, (and also because I guess this will be called just before it is going to be destroyed).

Quoted 2 lines
	u8			type;

Either a type (0 for in-kernel, 1 for userspace, >1 for BPF) or a name.

Quoted 5 lines
	struct module		*owner;
	struct list_head	list;

	void (*init)(struct mptcp_sock *msk);
	void (*release)(struct mptcp_sock *msk);

Is the init/release done only once, or for each MPTCP connection handled by this PM?

Quoted 3 lines

} ____cacheline_aligned_in_smp;

Better to wait to have the full BPF interface and an example in the selftests before closing this I think.

Two last thing:

- better keeping the 'mptcp_pm' prefixes for the new helpers, e.g. mptcp_pm_register instead of mptcp_register_path_manager.

- for the commit title, maybe clearer to prefix them with 'mptcp: pm:', and even 'mptcp: pm: in-kernel:', 'mptcp: pm: userspace:' and 'mptcp:
pm: bpf' when it makes sense.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#6 lore raw

Hi Matt,

Thanks for your review.

Quoted 66 lines · Matthieu Baerts

Hi Geliang,

Quoted 20 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v3:
 - rename the 2nd parameter of get_local_id() from 'local' to 'skc'.
 - keep the 'msk_sport' check in mptcp_userspace_pm_get_local_id().
 - return 'err' instead of '0' in userspace_pm_subflow_create().
 - drop 'ret' variable inmptcp_pm_data_reset().
 - fix typos in commit log.

Depends on: "BPF path manager, part 3" v4
Based-on: <[email protected]>

v2:
 - update get_local_id interface in patch 2.

get_addr() and dump_addr() interfaces of BPF userspace pm are dropped
as Matt suggested.

Quoted 6 lines

In order to implement BPF userspace path manager, it is necessary to
unify the interfaces of the path manager. This set contains some cleanups and refactoring to unify the interfaces in kernel space. Finally, define a struct mptcp_pm_ops for a userspace path manager like this:

Thank you for this series.

From what I see, when a BPF path-manager is loaded, it will replace the
userspace one, right?

It looks a bit confusing to know when the (netlink) userspace PM is used, and when the BPF one is. Why not defining a new type instead? Similar to what we have with the packet scheduler? net.mptcp.pm_type could be extended to select a BPF one of a certain ID, no? (or a new type for BPF, then another sysctl to select the name?)

Why not, instead, and similar to the scheduler, have a proper path-manager interface?

For the moment, when the core gets something that might interest the PM,
it will directly call a PM helper, then the right PM is picked thanks to
mptcp_pm_is_userspace() or mptcp_pm_is_kernel(). That starts to get a bit messy when we want to add more PMs. Instead, the core could simply
use the new ops structure, using a pointer stored in the msk.

In other words, when the core needs to notify the PM, it will simply call (directly, or via the PM worker): msk->pm.ops-

Quoted 1 line

something_happened()

(or via helpers in pm.c that could check if the callback is set, and call mptcp_event() for example)

That way, we have a clear separation of all the different PMs, and the
interface is clear to understand the interactions between the core and
the PMs.

Quoted 4 lines

WDYT?

I hope this doesn't change all your plans. But I think having such interface would help for the maintenance in general.

It would be best if struct mptcp_pm_ops could be used to represent both userspace pm and in-kernel pm, but it's not easy to represent in-kernel pm right now, and the code in pm_netlink.c needs to be adjusted. So I still use struct mptcp_pm_ops to implement MPTCP_PM_TYPE_BPF_USERSPACE first in the set, and use mptcp_pm_is_userspace() function to distinguish different PMs.

In the future, if we feel it's necessary, we can add a MPTCP_PM_TYPE_BPF_KERENL pm type to implement BPF in-kernel pm, and then gradually remove the use of mptcp_pm_is_userspace() and mptcp_pm_is_kernel().

Thanks,
-Geliang

Quoted 90 lines
Quoted 12 lines

struct mptcp_pm_ops {
int (*address_announce)(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local);
int (*address_remove)(struct mptcp_sock *msk, u8 id); int (*subflow_create)(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local, struct mptcp_addr_info *remote);
int (*subflow_destroy)(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local, struct mptcp_addr_info *remote);

Small detail: I would add a 'd' at the end to clearly understand it is
linked to an event, not an action, e.g. a new address has just been announced, here is a notification for the PM. So:

  address_announced
  address_removed
  subflow_created
  subflow_destroyed

Quoted 7 lines

int (*get_local_id)(struct mptcp_sock *msk,
    struct mptcp_pm_addr_entry *skc);
u8 (*get_flags)(struct mptcp_sock *msk,
struct mptcp_addr_info *skc);
int (*set_flags)(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *local,
struct mptcp_addr_info *remote);

I think it should only be get_priority and set_priority (i.e. backup):
the core doesn't need to know the other (internal) flags.

Also, when looking at mptcp_event_type, I think some events are missing
here for a PM to handle the different cases:

  created: a new MPTCP has been created, to init some stuff
  established: fully established connection, the PM can trigger actions
  closed: to free some stuff

And probably 'listerner_created' and 'listener_closed' too.

One last thing; I guess the current 'subflow_created' is more a 'subflow_established', no?
And 'subflow_destroyed' could be 'subflow_closed' to keep the same name,
(and also because I guess this will be called just before it is going to
be destroyed).

Quoted 2 lines

u8 type;

Either a type (0 for in-kernel, 1 for userspace, >1 for BPF) or a name.

Quoted 5 lines

struct module *owner;
struct list_head list;

void (*init)(struct mptcp_sock *msk);
void (*release)(struct mptcp_sock *msk);

Is the init/release done only once, or for each MPTCP connection handled
by this PM?

Quoted 3 lines

} ____cacheline_aligned_in_smp;

Better to wait to have the full BPF interface and an example in the selftests before closing this I think.

Two last thing:

- better keeping the 'mptcp_pm' prefixes for the new helpers, e.g. mptcp_pm_register instead of mptcp_register_path_manager.

- for the commit title, maybe clearer to prefix them with 'mptcp:
pm:',
and even 'mptcp: pm: in-kernel:', 'mptcp: pm: userspace:' and 'mptcp:
pm: bpf' when it makes sense.

Cheers,
Matt

author reviewer
#7 lore raw

Hi Matt,

Quoted 85 lines · Geliang Tang

Hi Matt,

Thanks for your review.

Quoted 75 lines · Matthieu Baerts

Hi Geliang,

Quoted 21 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v3:
 - rename the 2nd parameter of get_local_id() from 'local' to 'skc'.
 - keep the 'msk_sport' check in mptcp_userspace_pm_get_local_id().
 - return 'err' instead of '0' in userspace_pm_subflow_create().
 - drop 'ret' variable inmptcp_pm_data_reset().
 - fix typos in commit log.

Depends on: "BPF path manager, part 3" v4
Based-on: <[email protected]>

v2:
 - update get_local_id interface in patch 2.

get_addr() and dump_addr() interfaces of BPF userspace pm are dropped
as Matt suggested.

Quoted 7 lines

In order to implement BPF userspace path manager, it is necessary to
unify the interfaces of the path manager. This set contains some cleanups and refactoring to unify the interfaces in kernel space. Finally, define a struct mptcp_pm_ops for a userspace path manager
like this:

Thank you for this series.

From what I see, when a BPF path-manager is loaded, it will replace the
userspace one, right?

It looks a bit confusing to know when the (netlink) userspace PM is used, and when the BPF one is. Why not defining a new type instead? Similar to what we have with the packet scheduler? net.mptcp.pm_type
could be extended to select a BPF one of a certain ID, no? (or a new
type for BPF, then another sysctl to select the name?)

Why not, instead, and similar to the scheduler, have a proper path-manager interface?

For the moment, when the core gets something that might interest the
PM,
it will directly call a PM helper, then the right PM is picked thanks
to
mptcp_pm_is_userspace() or mptcp_pm_is_kernel(). That starts to get a
bit messy when we want to add more PMs. Instead, the core could simply
use the new ops structure, using a pointer stored in the msk.

In other words, when the core needs to notify the PM, it will simply
call (directly, or via the PM worker): msk->pm.ops-

Quoted 1 line

something_happened()

(or via helpers in pm.c that could check if the callback is set, and
call mptcp_event() for example)

That way, we have a clear separation of all the different PMs, and the
interface is clear to understand the interactions between the core and
the PMs.

Quoted 4 lines

WDYT?

I hope this doesn't change all your plans. But I think having such interface would help for the maintenance in general.

Quoted 9 lines

It would be best if struct mptcp_pm_ops could be used to represent both
userspace pm and in-kernel pm, but it's not easy to represent in- kernel
pm right now, and the code in pm_netlink.c needs to be adjusted. So I still use struct mptcp_pm_ops to implement MPTCP_PM_TYPE_BPF_USERSPACE
first in the set, and use mptcp_pm_is_userspace() function to distinguish different PMs.

I have made some new progress recently. I adjusted the code in pm_netlink.c and implemented get_local_id(), get_priority() and set_priority() interfaces for in-kernel pm. It seems that we can indeed use struct mptcp_pm_ops to represent both userspace pm and in-kernel pm, and then remove the use of mptcp_pm_is_userspace(). I will update the new version of this set in the near future.

Thanks,
-Geliang

Quoted 103 lines

In the future, if we feel it's necessary, we can add a MPTCP_PM_TYPE_BPF_KERENL pm type to implement BPF in-kernel pm, and then gradually remove the use of mptcp_pm_is_userspace() and mptcp_pm_is_kernel().

Thanks,
-Geliang

Quoted 92 lines
Quoted 12 lines

struct mptcp_pm_ops {
 int (*address_announce)(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local);
 int (*address_remove)(struct mptcp_sock *msk, u8 id); int (*subflow_create)(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local, struct mptcp_addr_info *remote);
 int (*subflow_destroy)(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local, struct mptcp_addr_info *remote);

Small detail: I would add a 'd' at the end to clearly understand it is
linked to an event, not an action, e.g. a new address has just been announced, here is a notification for the PM. So:

  address_announced
  address_removed
  subflow_created
  subflow_destroyed

Quoted 7 lines

 int (*get_local_id)(struct mptcp_sock *msk,
     struct mptcp_pm_addr_entry *skc);
 u8 (*get_flags)(struct mptcp_sock *msk,
 struct mptcp_addr_info *skc);
 int (*set_flags)(struct mptcp_sock *msk,
 struct mptcp_pm_addr_entry *local,
 struct mptcp_addr_info *remote);

I think it should only be get_priority and set_priority (i.e. backup):
the core doesn't need to know the other (internal) flags.

Also, when looking at mptcp_event_type, I think some events are missing
here for a PM to handle the different cases:

  created: a new MPTCP has been created, to init some stuff
  established: fully established connection, the PM can trigger actions
  closed: to free some stuff

And probably 'listerner_created' and 'listener_closed' too.

One last thing; I guess the current 'subflow_created' is more a 'subflow_established', no?
And 'subflow_destroyed' could be 'subflow_closed' to keep the same name,
(and also because I guess this will be called just before it is going
to
be destroyed).

Quoted 2 lines

 u8 type;

Either a type (0 for in-kernel, 1 for userspace, >1 for BPF) or a name.

Quoted 5 lines

 struct module *owner;
 struct list_head list;

 void (*init)(struct mptcp_sock *msk);
 void (*release)(struct mptcp_sock *msk);

Is the init/release done only once, or for each MPTCP connection handled
by this PM?

Quoted 3 lines

} ____cacheline_aligned_in_smp;

Better to wait to have the full BPF interface and an example in the selftests before closing this I think.

Two last thing:

- better keeping the 'mptcp_pm' prefixes for the new helpers, e.g. mptcp_pm_register instead of mptcp_register_path_manager.

- for the commit title, maybe clearer to prefix them with 'mptcp:
pm:',
and even 'mptcp: pm: in-kernel:', 'mptcp: pm: userspace:' and 'mptcp:
pm: bpf' when it makes sense.

Cheers,
Matt