Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang committed Oct 25, 2024
1 parent 8e9349d commit 0954a43
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 59 deletions.
7 changes: 7 additions & 0 deletions net/mptcp/bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/btf_ids.h>
#include <net/bpf_sk_storage.h>
#include "protocol.h"
#include "mib.h"

#ifdef CONFIG_BPF_JIT
static struct bpf_struct_ops bpf_mptcp_pm_ops,
Expand Down Expand Up @@ -686,6 +687,11 @@ __bpf_kfunc static void bpf_ipv6_addr_set_v4mapped(const __be32 addr,
#endif
}

__bpf_kfunc static void mptcp_inc_stats_rmsubflow(struct sock *sk)
{
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RMSUBFLOW);
}

__bpf_kfunc static bool bpf_mptcp_subflow_queues_empty(struct sock *sk)
{
return tcp_rtx_queue_empty(sk);
Expand Down Expand Up @@ -737,6 +743,7 @@ BTF_ID_FLAGS(func, mptcp_pm_remove_addr_entry, KF_SLEEPABLE)
BTF_ID_FLAGS(func, __mptcp_subflow_connect, KF_SLEEPABLE)
BTF_ID_FLAGS(func, mptcp_subflow_shutdown, KF_SLEEPABLE)
BTF_ID_FLAGS(func, mptcp_close_ssk, KF_SLEEPABLE)
BTF_ID_FLAGS(func, mptcp_inc_stats_rmsubflow)
BTF_ID_FLAGS(func, mptcp_pm_nl_mp_prio_send_ack, KF_SLEEPABLE)
BTF_ID_FLAGS(func, mptcp_subflow_active)
BTF_ID_FLAGS(func, mptcp_set_timeout)
Expand Down
51 changes: 30 additions & 21 deletions net/mptcp/pm_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,20 @@ __lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned int id)
}

static struct mptcp_pm_addr_entry *
__lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info)
__lookup_addr_by_id_rcu(struct pm_nl_pernet *pernet, unsigned int id)
{
struct mptcp_pm_addr_entry *entry;

list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
if (entry->addr.id == id)
return entry;
}
return NULL;
}

static struct mptcp_pm_addr_entry *
__lookup_addr_rcu(struct pm_nl_pernet *pernet,
const struct mptcp_addr_info *info)
{
struct mptcp_pm_addr_entry *entry;

Expand Down Expand Up @@ -544,7 +557,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)

mptcp_local_address((struct sock_common *)msk->first, &mpc_addr);
rcu_read_lock();
entry = __lookup_addr(pernet, &mpc_addr);
entry = __lookup_addr_rcu(pernet, &mpc_addr);
if (entry) {
__clear_bit(entry->addr.id, msk->pm.id_avail_bitmap.map);
msk->mpc_endpoint_id = entry->addr.id;
Expand Down Expand Up @@ -1127,14 +1140,13 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry
{
struct mptcp_pm_addr_entry *entry;
struct pm_nl_pernet *pernet;
int ret = -1;
int ret;

pernet = pm_nl_get_pernet_from_msk(msk);

rcu_read_lock();
entry = __lookup_addr(pernet, &local->addr);
if (entry)
ret = entry->addr.id;
entry = __lookup_addr_rcu(pernet, &local->addr);
ret = entry ? entry->addr.id : -1;
rcu_read_unlock();
if (ret >= 0)
return ret;
Expand All @@ -1156,12 +1168,11 @@ u8 mptcp_pm_nl_get_flags(struct mptcp_sock *msk, struct mptcp_addr_info *skc)
{
struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
struct mptcp_pm_addr_entry *entry;
u8 flags = 0;
u8 flags;

rcu_read_lock();
entry = __lookup_addr(pernet, skc);
if (entry)
flags = entry->flags;
entry = __lookup_addr_rcu(pernet, skc);
flags = entry ? entry->flags : 0;
rcu_read_unlock();

return flags;
Expand Down Expand Up @@ -1779,13 +1790,13 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,

pernet = pm_nl_get_pernet(net);

spin_lock_bh(&pernet->lock);
entry = __lookup_addr_by_id(pernet, id);
rcu_read_lock();
entry = __lookup_addr_by_id_rcu(pernet, id);
if (entry) {
*addr = *entry;
ret = 0;
}
spin_unlock_bh(&pernet->lock);
rcu_read_unlock();

return ret;
}
Expand Down Expand Up @@ -1849,9 +1860,7 @@ static int mptcp_pm_nl_dump_addr(struct mptcp_id_bitmap *bitmap,

pernet = pm_nl_get_pernet(net);

spin_lock_bh(&pernet->lock);
bitmap_copy(bitmap->map, pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1);
spin_unlock_bh(&pernet->lock);

return 0;
}
Expand Down Expand Up @@ -2047,25 +2056,25 @@ static int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *loc,
if (loc->flags & MPTCP_PM_ADDR_FLAG_BACKUP)
bkup = 1;

spin_lock_bh(&pernet->lock);
entry = lookup_by_id ? __lookup_addr_by_id(pernet, loc->addr.id) :
__lookup_addr(pernet, &loc->addr);
rcu_read_lock();
entry = lookup_by_id ? __lookup_addr_by_id_rcu(pernet, loc->addr.id) :
__lookup_addr_rcu(pernet, &loc->addr);
if (!entry) {
spin_unlock_bh(&pernet->lock);
rcu_read_unlock();
GENL_SET_ERR_MSG(info, "address not found");
return -EINVAL;
}
if ((loc->flags & MPTCP_PM_ADDR_FLAG_FULLMESH) &&
(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
spin_unlock_bh(&pernet->lock);
rcu_read_unlock();
GENL_SET_ERR_MSG(info, "invalid addr flags");
return -EINVAL;
}

changed = (loc->flags ^ entry->flags) & mask;
entry->flags = (entry->flags & ~mask) | (loc->flags & mask);
*loc = *entry;
spin_unlock_bh(&pernet->lock);
rcu_read_unlock();

mptcp_nl_set_flags(net, &loc->addr, bkup, changed);
return 0;
Expand Down
2 changes: 2 additions & 0 deletions tools/testing/selftests/bpf/progs/mptcp_bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extern bool CONFIG_MPTCP_IPV6 __kconfig __weak;
#define RCV_SHUTDOWN 1
#define SEND_SHUTDOWN 2

#define ESRCH 3 /* No such process */
#define ENOMEM 12 /* Out of Memory */
#define EINVAL 22 /* Invalid argument */

Expand Down Expand Up @@ -132,6 +133,7 @@ extern void bpf_ipv6_addr_set_v4mapped(const __be32 addr,
extern void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how) __ksym;
extern void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
struct mptcp_subflow_context *subflow) __ksym;
extern void mptcp_inc_stats_rmsubflow(struct sock *sk) __ksym;

extern int mptcp_pm_nl_mp_prio_send_ack(struct mptcp_sock *msk,
struct mptcp_addr_info *addr,
Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/bpf/progs/mptcp_bpf_bytes.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ int BPF_PROG(trace_mptcp_sched_get_send, struct mptcp_sock *msk)
tp = bpf_core_cast(ssk, struct tcp_sock);

if (subflow->subflow_id == 1) {
bpf_printk("bytes 1: sent %lu received %lu subflows %u", tp->bytes_sent, tp->bytes_received, msk->pm.subflows);
//bpf_printk("bytes 1: sent %lu received %lu subflows %u", tp->bytes_sent, tp->bytes_received, msk->pm.subflows);
bytes_sent_1 += tp->bytes_sent;
} else if (subflow->subflow_id == 2) {
bpf_printk("bytes 2: sent %lu received %lu subflows %u", tp->bytes_sent, tp->bytes_received, msk->pm.subflows);
//bpf_printk("bytes 2: sent %lu received %lu subflows %u", tp->bytes_sent, tp->bytes_received, msk->pm.subflows);
bytes_sent_2 += tp->bytes_sent;
}
}
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ int BPF_PROG(bpf_rr_get_subflow, struct mptcp_sock *msk,
out:
next = bpf_core_cast(next, struct mptcp_subflow_context);
mptcp_subflow_set_scheduled(next, true);
//bpf_printk("rr subflow=%u/%u", next->subflow_id, msk->pm.subflows + 1);
ptr->last_snd = mptcp_subflow_tcp_sock(next);
return 0;
}
Expand Down
Loading

0 comments on commit 0954a43

Please sign in to comment.