mptcp: add struct mptcp_sched_ops
JIRA: https://issues.redhat.com/browse/RHEL-15036
Tested: LNST, Tier1
Upstream commit:
commit 740ebe35bd3f5c4ff8ec60e5e521e47ea8f5492c
Author: Geliang Tang <geliang.tang@suse.com>
Date: Mon Aug 21 15:25:14 2023 -0700
mptcp: add struct mptcp_sched_ops
This patch defines struct mptcp_sched_ops, which has three struct members,
name, owner and list, and four function pointers: init(), release() and
get_subflow().
The scheduler function get_subflow() have a struct mptcp_sched_data
parameter, which contains a reinject flag for retrans or not, a subflows
number and a mptcp_subflow_context array.
Add the scheduler registering, unregistering and finding functions to add,
delete and find a packet scheduler on the global list mptcp_sched_list.
Acked-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
Signed-off-by: Mat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20230821-upstream-net-next-20230818-v1-3-0c860fb256a8@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-10-31 16:31:50 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/* Multipath TCP
|
|
|
|
*
|
|
|
|
* Copyright (c) 2022, SUSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) "MPTCP: " fmt
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/rculist.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include "protocol.h"
|
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(mptcp_sched_list_lock);
|
|
|
|
static LIST_HEAD(mptcp_sched_list);
|
|
|
|
|
2023-10-31 16:32:45 +00:00
|
|
|
static int mptcp_sched_default_get_subflow(struct mptcp_sock *msk,
|
|
|
|
struct mptcp_sched_data *data)
|
|
|
|
{
|
|
|
|
struct sock *ssk;
|
|
|
|
|
|
|
|
ssk = data->reinject ? mptcp_subflow_get_retrans(msk) :
|
|
|
|
mptcp_subflow_get_send(msk);
|
|
|
|
if (!ssk)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
mptcp_subflow_set_scheduled(mptcp_subflow_ctx(ssk), true);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct mptcp_sched_ops mptcp_sched_default = {
|
|
|
|
.get_subflow = mptcp_sched_default_get_subflow,
|
|
|
|
.name = "default",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
mptcp: add struct mptcp_sched_ops
JIRA: https://issues.redhat.com/browse/RHEL-15036
Tested: LNST, Tier1
Upstream commit:
commit 740ebe35bd3f5c4ff8ec60e5e521e47ea8f5492c
Author: Geliang Tang <geliang.tang@suse.com>
Date: Mon Aug 21 15:25:14 2023 -0700
mptcp: add struct mptcp_sched_ops
This patch defines struct mptcp_sched_ops, which has three struct members,
name, owner and list, and four function pointers: init(), release() and
get_subflow().
The scheduler function get_subflow() have a struct mptcp_sched_data
parameter, which contains a reinject flag for retrans or not, a subflows
number and a mptcp_subflow_context array.
Add the scheduler registering, unregistering and finding functions to add,
delete and find a packet scheduler on the global list mptcp_sched_list.
Acked-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
Signed-off-by: Mat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20230821-upstream-net-next-20230818-v1-3-0c860fb256a8@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-10-31 16:31:50 +00:00
|
|
|
/* Must be called with rcu read lock held */
|
|
|
|
struct mptcp_sched_ops *mptcp_sched_find(const char *name)
|
|
|
|
{
|
|
|
|
struct mptcp_sched_ops *sched, *ret = NULL;
|
|
|
|
|
|
|
|
list_for_each_entry_rcu(sched, &mptcp_sched_list, list) {
|
|
|
|
if (!strcmp(sched->name, name)) {
|
|
|
|
ret = sched;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mptcp_register_scheduler(struct mptcp_sched_ops *sched)
|
|
|
|
{
|
|
|
|
if (!sched->get_subflow)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
spin_lock(&mptcp_sched_list_lock);
|
|
|
|
if (mptcp_sched_find(sched->name)) {
|
|
|
|
spin_unlock(&mptcp_sched_list_lock);
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
list_add_tail_rcu(&sched->list, &mptcp_sched_list);
|
|
|
|
spin_unlock(&mptcp_sched_list_lock);
|
|
|
|
|
mptcp: pr_debug: add missing \n at the end
JIRA: https://issues.redhat.com/browse/RHEL-62871
Upstream Status: net.git commit cb41b195e634d3f1ecfcd845314e64fd4bb3c7aa
Conflicts:
- net/mptcp/protocol.c: preserve the old version of inet_csk_accept()
as we don't have upstream commit 92ef0fd55ac8 ("net: change proto and
proto_ops accept type")
commit cb41b195e634d3f1ecfcd845314e64fd4bb3c7aa
Author: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Date: Mon Aug 26 19:11:21 2024 +0200
mptcp: pr_debug: add missing \n at the end
pr_debug() have been added in various places in MPTCP code to help
developers to debug some situations. With the dynamic debug feature, it
is easy to enable all or some of them, and asks users to reproduce
issues with extra debug.
Many of these pr_debug() don't end with a new line, while no 'pr_cont()'
are used in MPTCP code. So the goal was not to display multiple debug
messages on one line: they were then not missing the '\n' on purpose.
Not having the new line at the end causes these messages to be printed
with a delay, when something else needs to be printed. This issue is not
visible when many messages need to be printed, but it is annoying and
confusing when only specific messages are expected, e.g.
# echo "func mptcp_pm_add_addr_echoed +fmp" \
> /sys/kernel/debug/dynamic_debug/control
# ./mptcp_join.sh "signal address"; \
echo "$(awk '{print $1}' /proc/uptime) - end"; \
sleep 5s; \
echo "$(awk '{print $1}' /proc/uptime) - restart"; \
./mptcp_join.sh "signal address"
013 signal address
(...)
10.75 - end
15.76 - restart
013 signal address
[ 10.367935] mptcp:mptcp_pm_add_addr_echoed: MPTCP: msk=(...)
(...)
=> a delay of 5 seconds: printed with a 10.36 ts, but after 'restart'
which was printed at the 15.76 ts.
The 'Fixes' tag here below points to the first pr_debug() used without
'\n' in net/mptcp. This patch could be split in many small ones, with
different Fixes tag, but it doesn't seem worth it, because it is easy to
re-generate this patch with this simple 'sed' command:
git grep -l pr_debug -- net/mptcp |
xargs sed -i "s/\(pr_debug(\".*[^n]\)\(\"[,)]\)/\1\\\n\2/g"
So in case of conflicts, simply drop the modifications, and launch this
command.
Fixes: f870fa0b5768 ("mptcp: Add MPTCP socket stubs")
Cc: stable@vger.kernel.org
Reviewed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20240826-net-mptcp-close-extra-sf-fin-v1-4-905199fe1172@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
2024-10-16 16:55:06 +00:00
|
|
|
pr_debug("%s registered\n", sched->name);
|
mptcp: add struct mptcp_sched_ops
JIRA: https://issues.redhat.com/browse/RHEL-15036
Tested: LNST, Tier1
Upstream commit:
commit 740ebe35bd3f5c4ff8ec60e5e521e47ea8f5492c
Author: Geliang Tang <geliang.tang@suse.com>
Date: Mon Aug 21 15:25:14 2023 -0700
mptcp: add struct mptcp_sched_ops
This patch defines struct mptcp_sched_ops, which has three struct members,
name, owner and list, and four function pointers: init(), release() and
get_subflow().
The scheduler function get_subflow() have a struct mptcp_sched_data
parameter, which contains a reinject flag for retrans or not, a subflows
number and a mptcp_subflow_context array.
Add the scheduler registering, unregistering and finding functions to add,
delete and find a packet scheduler on the global list mptcp_sched_list.
Acked-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
Signed-off-by: Mat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20230821-upstream-net-next-20230818-v1-3-0c860fb256a8@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-10-31 16:31:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched)
|
|
|
|
{
|
2023-10-31 16:32:45 +00:00
|
|
|
if (sched == &mptcp_sched_default)
|
|
|
|
return;
|
|
|
|
|
mptcp: add struct mptcp_sched_ops
JIRA: https://issues.redhat.com/browse/RHEL-15036
Tested: LNST, Tier1
Upstream commit:
commit 740ebe35bd3f5c4ff8ec60e5e521e47ea8f5492c
Author: Geliang Tang <geliang.tang@suse.com>
Date: Mon Aug 21 15:25:14 2023 -0700
mptcp: add struct mptcp_sched_ops
This patch defines struct mptcp_sched_ops, which has three struct members,
name, owner and list, and four function pointers: init(), release() and
get_subflow().
The scheduler function get_subflow() have a struct mptcp_sched_data
parameter, which contains a reinject flag for retrans or not, a subflows
number and a mptcp_subflow_context array.
Add the scheduler registering, unregistering and finding functions to add,
delete and find a packet scheduler on the global list mptcp_sched_list.
Acked-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
Signed-off-by: Mat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20230821-upstream-net-next-20230818-v1-3-0c860fb256a8@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-10-31 16:31:50 +00:00
|
|
|
spin_lock(&mptcp_sched_list_lock);
|
|
|
|
list_del_rcu(&sched->list);
|
|
|
|
spin_unlock(&mptcp_sched_list_lock);
|
|
|
|
}
|
2023-10-31 16:32:03 +00:00
|
|
|
|
2023-10-31 16:32:45 +00:00
|
|
|
void mptcp_sched_init(void)
|
|
|
|
{
|
|
|
|
mptcp_register_scheduler(&mptcp_sched_default);
|
|
|
|
}
|
|
|
|
|
2023-10-31 16:32:03 +00:00
|
|
|
int mptcp_init_sched(struct mptcp_sock *msk,
|
|
|
|
struct mptcp_sched_ops *sched)
|
|
|
|
{
|
|
|
|
if (!sched)
|
2023-10-31 16:32:45 +00:00
|
|
|
sched = &mptcp_sched_default;
|
2023-10-31 16:32:03 +00:00
|
|
|
|
|
|
|
if (!bpf_try_module_get(sched, sched->owner))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
msk->sched = sched;
|
|
|
|
if (msk->sched->init)
|
|
|
|
msk->sched->init(msk);
|
|
|
|
|
mptcp: pr_debug: add missing \n at the end
JIRA: https://issues.redhat.com/browse/RHEL-62871
Upstream Status: net.git commit cb41b195e634d3f1ecfcd845314e64fd4bb3c7aa
Conflicts:
- net/mptcp/protocol.c: preserve the old version of inet_csk_accept()
as we don't have upstream commit 92ef0fd55ac8 ("net: change proto and
proto_ops accept type")
commit cb41b195e634d3f1ecfcd845314e64fd4bb3c7aa
Author: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Date: Mon Aug 26 19:11:21 2024 +0200
mptcp: pr_debug: add missing \n at the end
pr_debug() have been added in various places in MPTCP code to help
developers to debug some situations. With the dynamic debug feature, it
is easy to enable all or some of them, and asks users to reproduce
issues with extra debug.
Many of these pr_debug() don't end with a new line, while no 'pr_cont()'
are used in MPTCP code. So the goal was not to display multiple debug
messages on one line: they were then not missing the '\n' on purpose.
Not having the new line at the end causes these messages to be printed
with a delay, when something else needs to be printed. This issue is not
visible when many messages need to be printed, but it is annoying and
confusing when only specific messages are expected, e.g.
# echo "func mptcp_pm_add_addr_echoed +fmp" \
> /sys/kernel/debug/dynamic_debug/control
# ./mptcp_join.sh "signal address"; \
echo "$(awk '{print $1}' /proc/uptime) - end"; \
sleep 5s; \
echo "$(awk '{print $1}' /proc/uptime) - restart"; \
./mptcp_join.sh "signal address"
013 signal address
(...)
10.75 - end
15.76 - restart
013 signal address
[ 10.367935] mptcp:mptcp_pm_add_addr_echoed: MPTCP: msk=(...)
(...)
=> a delay of 5 seconds: printed with a 10.36 ts, but after 'restart'
which was printed at the 15.76 ts.
The 'Fixes' tag here below points to the first pr_debug() used without
'\n' in net/mptcp. This patch could be split in many small ones, with
different Fixes tag, but it doesn't seem worth it, because it is easy to
re-generate this patch with this simple 'sed' command:
git grep -l pr_debug -- net/mptcp |
xargs sed -i "s/\(pr_debug(\".*[^n]\)\(\"[,)]\)/\1\\\n\2/g"
So in case of conflicts, simply drop the modifications, and launch this
command.
Fixes: f870fa0b5768 ("mptcp: Add MPTCP socket stubs")
Cc: stable@vger.kernel.org
Reviewed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20240826-net-mptcp-close-extra-sf-fin-v1-4-905199fe1172@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
2024-10-16 16:55:06 +00:00
|
|
|
pr_debug("sched=%s\n", msk->sched->name);
|
2023-10-31 16:32:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mptcp_release_sched(struct mptcp_sock *msk)
|
|
|
|
{
|
|
|
|
struct mptcp_sched_ops *sched = msk->sched;
|
|
|
|
|
|
|
|
if (!sched)
|
|
|
|
return;
|
|
|
|
|
|
|
|
msk->sched = NULL;
|
|
|
|
if (sched->release)
|
|
|
|
sched->release(msk);
|
|
|
|
|
|
|
|
bpf_module_put(sched, sched->owner);
|
|
|
|
}
|
2023-10-31 16:32:09 +00:00
|
|
|
|
|
|
|
void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,
|
|
|
|
bool scheduled)
|
|
|
|
{
|
|
|
|
WRITE_ONCE(subflow->scheduled, scheduled);
|
|
|
|
}
|
2023-10-31 16:32:17 +00:00
|
|
|
|
|
|
|
int mptcp_sched_get_send(struct mptcp_sock *msk)
|
|
|
|
{
|
|
|
|
struct mptcp_subflow_context *subflow;
|
|
|
|
struct mptcp_sched_data data;
|
|
|
|
|
2023-10-31 16:32:28 +00:00
|
|
|
msk_owned_by_me(msk);
|
|
|
|
|
|
|
|
/* the following check is moved out of mptcp_subflow_get_send */
|
|
|
|
if (__mptcp_check_fallback(msk)) {
|
|
|
|
if (msk->first &&
|
|
|
|
__tcp_can_send(msk->first) &&
|
|
|
|
sk_stream_memory_free(msk->first)) {
|
|
|
|
mptcp_subflow_set_scheduled(mptcp_subflow_ctx(msk->first), true);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2023-10-31 16:32:17 +00:00
|
|
|
mptcp_for_each_subflow(msk, subflow) {
|
|
|
|
if (READ_ONCE(subflow->scheduled))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.reinject = false;
|
2023-10-31 16:32:45 +00:00
|
|
|
if (msk->sched == &mptcp_sched_default || !msk->sched)
|
|
|
|
return mptcp_sched_default_get_subflow(msk, &data);
|
2023-10-31 16:32:17 +00:00
|
|
|
return msk->sched->get_subflow(msk, &data);
|
|
|
|
}
|
|
|
|
|
|
|
|
int mptcp_sched_get_retrans(struct mptcp_sock *msk)
|
|
|
|
{
|
|
|
|
struct mptcp_subflow_context *subflow;
|
|
|
|
struct mptcp_sched_data data;
|
|
|
|
|
2023-10-31 16:32:37 +00:00
|
|
|
msk_owned_by_me(msk);
|
|
|
|
|
|
|
|
/* the following check is moved out of mptcp_subflow_get_retrans */
|
|
|
|
if (__mptcp_check_fallback(msk))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2023-10-31 16:32:17 +00:00
|
|
|
mptcp_for_each_subflow(msk, subflow) {
|
|
|
|
if (READ_ONCE(subflow->scheduled))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.reinject = true;
|
2023-10-31 16:32:45 +00:00
|
|
|
if (msk->sched == &mptcp_sched_default || !msk->sched)
|
|
|
|
return mptcp_sched_default_get_subflow(msk, &data);
|
2023-10-31 16:32:17 +00:00
|
|
|
return msk->sched->get_subflow(msk, &data);
|
|
|
|
}
|