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 Nov 1, 2024
1 parent 009a8b6 commit 722a742
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 60 deletions.
10 changes: 8 additions & 2 deletions include/net/mptcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ struct mptcp_info;
struct mptcp_sock;
struct seq_file;
struct mptcp_pm_addr_entry;
struct mptcp_id_bitmap;

/* MPTCP sk_buff extension data */
struct mptcp_ext {
Expand Down Expand Up @@ -104,6 +103,9 @@ struct mptcp_out_options {

#define MPTCP_SUBFLOWS_MAX 8

/* max value of mptcp_addr_info.id */
#define MPTCP_PM_MAX_ADDR_ID U8_MAX

struct mptcp_sched_data {
bool reinject;
};
Expand All @@ -120,6 +122,10 @@ struct mptcp_sched_ops {
void (*release)(struct mptcp_sock *msk);
} ____cacheline_aligned_in_smp;

typedef struct {
DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1);
} mptcp_pm_addr_id_bitmap_t;

struct mptcp_pm_ops {
int (*address_announce)(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *local);
Expand All @@ -137,7 +143,7 @@ struct mptcp_pm_ops {
struct mptcp_pm_addr_entry *(*get_addr)(struct mptcp_sock *msk,
u8 id);
int (*dump_addr)(struct mptcp_sock *msk,
struct mptcp_id_bitmap *bitmap);
mptcp_pm_addr_id_bitmap_t *bitmap);
int (*set_flags)(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *local,
struct mptcp_addr_info *remote);
Expand Down
10 changes: 5 additions & 5 deletions net/mptcp/bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ __bpf_mptcp_pm_get_addr(struct mptcp_sock *msk, u8 id)
}

static int __bpf_mptcp_pm_dump_addr(struct mptcp_sock *msk,
struct mptcp_id_bitmap *bitmap)
mptcp_pm_addr_id_bitmap_t *bitmap)
{
return 0;
}
Expand Down Expand Up @@ -639,22 +639,22 @@ __bpf_kfunc static bool bpf_mptcp_addresses_equal(const struct mptcp_addr_info *
return mptcp_addresses_equal(a, b, use_port);
}

__bpf_kfunc static void bpf_bitmap_zero(struct mptcp_id_bitmap *bitmap)
__bpf_kfunc static void bpf_bitmap_zero(mptcp_pm_addr_id_bitmap_t *bitmap)
{
bitmap_zero(bitmap->map, MPTCP_PM_MAX_ADDR_ID + 1);
}

__bpf_kfunc static bool bpf_test_bit(__u8 id, struct mptcp_id_bitmap *bitmap)
__bpf_kfunc static bool bpf_test_bit(__u8 id, mptcp_pm_addr_id_bitmap_t *bitmap)
{
return test_bit(id, bitmap->map);
}

__bpf_kfunc static void bpf_set_bit(__u8 id, struct mptcp_id_bitmap *bitmap)
__bpf_kfunc static void bpf_set_bit(__u8 id, mptcp_pm_addr_id_bitmap_t *bitmap)
{
__set_bit(id, bitmap->map);
}

__bpf_kfunc static __u8 bpf_next_bit(struct mptcp_id_bitmap *bitmap)
__bpf_kfunc static __u8 bpf_next_bit(mptcp_pm_addr_id_bitmap_t *bitmap)
{
return find_next_zero_bit(bitmap->map, MPTCP_PM_MAX_ADDR_ID + 1, 1);
}
Expand Down
4 changes: 2 additions & 2 deletions net/mptcp/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
return mptcp_pm_nl_get_addr(id, addr, info);
}

int mptcp_pm_dump_addr(struct mptcp_id_bitmap *bitmap,
int mptcp_pm_dump_addr(unsigned long *bitmap,
const struct genl_info *info)
{
if (info->attrs[MPTCP_PM_ATTR_TOKEN])
Expand Down Expand Up @@ -554,7 +554,7 @@ void mptcp_pm_data_reset(struct mptcp_sock *msk)
WRITE_ONCE(pm->addr_signal, 0);
WRITE_ONCE(pm->remote_deny_join_id0, false);
pm->status = 0;
bitmap_fill(msk->pm.id_avail_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1);
bitmap_fill(msk->pm.id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
}

void mptcp_pm_data_init(struct mptcp_sock *msk)
Expand Down
50 changes: 25 additions & 25 deletions net/mptcp/pm_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct pm_nl_pernet {
unsigned int local_addr_max;
unsigned int subflows_max;
unsigned int next_id;
struct mptcp_id_bitmap id_bitmap;
DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
};

#define MPTCP_PM_ADDR_MAX 8
Expand Down Expand Up @@ -153,7 +153,7 @@ select_local_address(const struct pm_nl_pernet *pernet,
if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW))
continue;

if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap.map))
if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap))
continue;

*new_local = *entry;
Expand All @@ -179,7 +179,7 @@ select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk,
* can lead to additional addresses not being announced.
*/
list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap.map))
if (!test_bit(entry->addr.id, msk->pm.id_avail_bitmap))
continue;

if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
Expand Down Expand Up @@ -231,7 +231,7 @@ bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk)
struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);

if (msk->pm.subflows == mptcp_pm_get_subflows_max(msk) ||
(find_next_and_bit(pernet->id_bitmap.map, msk->pm.id_avail_bitmap.map,
(find_next_and_bit(pernet->id_bitmap, msk->pm.id_avail_bitmap,
MPTCP_PM_MAX_ADDR_ID + 1, 0) == MPTCP_PM_MAX_ADDR_ID + 1)) {
WRITE_ONCE(msk->pm.work_pending, false);
return false;
Expand Down Expand Up @@ -431,15 +431,15 @@ static unsigned int fill_remote_addresses_vec(struct mptcp_sock *msk,
msk->pm.subflows++;
addrs[i++] = remote;
} else {
struct mptcp_id_bitmap unavail_id;
DECLARE_BITMAP(unavail_id, MPTCP_PM_MAX_ADDR_ID + 1);

/* Forbid creation of new subflows matching existing
* ones, possibly already created by incoming ADD_ADDR
*/
bitmap_zero(unavail_id.map, MPTCP_PM_MAX_ADDR_ID + 1);
bitmap_zero(unavail_id, MPTCP_PM_MAX_ADDR_ID + 1);
mptcp_for_each_subflow(msk, subflow)
if (READ_ONCE(subflow->local_id) == local->id)
__set_bit(subflow->remote_id, unavail_id.map);
__set_bit(subflow->remote_id, unavail_id);

mptcp_for_each_subflow(msk, subflow) {
ssk = mptcp_subflow_tcp_sock(subflow);
Expand All @@ -448,7 +448,7 @@ static unsigned int fill_remote_addresses_vec(struct mptcp_sock *msk,
if (deny_id0 && !addrs[i].id)
continue;

if (test_bit(addrs[i].id, unavail_id.map))
if (test_bit(addrs[i].id, unavail_id))
continue;

if (!mptcp_pm_addr_families_match(sk, local, &addrs[i]))
Expand All @@ -458,7 +458,7 @@ static unsigned int fill_remote_addresses_vec(struct mptcp_sock *msk,
/* forbid creating multiple address towards
* this id
*/
__set_bit(addrs[i].id, unavail_id.map);
__set_bit(addrs[i].id, unavail_id);
msk->pm.subflows++;
i++;
}
Expand Down Expand Up @@ -559,7 +559,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
rcu_read_lock();
entry = __lookup_addr_rcu(pernet, &mpc_addr);
if (entry) {
__clear_bit(entry->addr.id, msk->pm.id_avail_bitmap.map);
__clear_bit(entry->addr.id, msk->pm.id_avail_bitmap);
msk->mpc_endpoint_id = entry->addr.id;
backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP);
}
Expand Down Expand Up @@ -597,7 +597,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
if (!mptcp_pm_alloc_anno_list(msk, &local.addr))
return;

__clear_bit(local.addr.id, msk->pm.id_avail_bitmap.map);
__clear_bit(local.addr.id, msk->pm.id_avail_bitmap);
msk->pm.add_addr_signaled++;

/* Special case for ID0: set the correct ID */
Expand Down Expand Up @@ -626,7 +626,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)

fullmesh = !!(local.flags & MPTCP_PM_ADDR_FLAG_FULLMESH);

__clear_bit(local.addr.id, msk->pm.id_avail_bitmap.map);
__clear_bit(local.addr.id, msk->pm.id_avail_bitmap);

/* Special case for ID0: set the correct ID */
if (local.addr.id == msk->mpc_endpoint_id)
Expand Down Expand Up @@ -990,7 +990,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
ret = -ERANGE;
goto out;
}
if (test_bit(entry->addr.id, pernet->id_bitmap.map)) {
if (test_bit(entry->addr.id, pernet->id_bitmap)) {
ret = -EBUSY;
goto out;
}
Expand Down Expand Up @@ -1024,7 +1024,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,

if (!entry->addr.id && needs_id) {
find_next:
entry->addr.id = find_next_zero_bit(pernet->id_bitmap.map,
entry->addr.id = find_next_zero_bit(pernet->id_bitmap,
MPTCP_PM_MAX_ADDR_ID + 1,
pernet->next_id);
if (!entry->addr.id && pernet->next_id != 1) {
Expand All @@ -1036,7 +1036,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
if (!entry->addr.id && needs_id)
goto out;

__set_bit(entry->addr.id, pernet->id_bitmap.map);
__set_bit(entry->addr.id, pernet->id_bitmap);
if (entry->addr.id > pernet->next_id)
pernet->next_id = entry->addr.id;

Expand Down Expand Up @@ -1472,7 +1472,7 @@ static bool mptcp_pm_remove_anno_addr(struct mptcp_sock *msk,
if (ret || force) {
spin_lock_bh(&msk->pm.lock);
if (ret) {
__set_bit(addr->id, msk->pm.id_avail_bitmap.map);
__set_bit(addr->id, msk->pm.id_avail_bitmap);
msk->pm.add_addr_signaled--;
}
mptcp_pm_remove_addr(msk, &list);
Expand All @@ -1484,7 +1484,7 @@ static bool mptcp_pm_remove_anno_addr(struct mptcp_sock *msk,
static void __mark_subflow_endp_available(struct mptcp_sock *msk, u8 id)
{
/* If it was marked as used, and not ID 0, decrement local_addr_used */
if (!__test_and_set_bit(id ? : msk->mpc_endpoint_id, msk->pm.id_avail_bitmap.map) &&
if (!__test_and_set_bit(id ? : msk->mpc_endpoint_id, msk->pm.id_avail_bitmap) &&
id && !WARN_ON_ONCE(msk->pm.local_addr_used == 0))
msk->pm.local_addr_used--;
}
Expand Down Expand Up @@ -1615,7 +1615,7 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info)

pernet->addrs--;
list_del_rcu(&entry->list);
__clear_bit(entry->addr.id, pernet->id_bitmap.map);
__clear_bit(entry->addr.id, pernet->id_bitmap);
spin_unlock_bh(&pernet->lock);

mptcp_nl_remove_subflow_and_signal_addr(sock_net(skb->sk), entry);
Expand Down Expand Up @@ -1675,7 +1675,7 @@ static void mptcp_pm_flush_addrs_and_subflows(struct mptcp_sock *msk,
if (slist.nr)
mptcp_pm_nl_rm_subflow_received(msk, &slist);
/* Reset counters: maybe some subflows have been removed before */
bitmap_fill(msk->pm.id_avail_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1);
bitmap_fill(msk->pm.id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
msk->pm.local_addr_used = 0;
spin_unlock_bh(&msk->pm.lock);
}
Expand Down Expand Up @@ -1733,7 +1733,7 @@ int mptcp_pm_nl_flush_addrs_doit(struct sk_buff *skb, struct genl_info *info)
list_splice_init(&pernet->local_addr_list, &free_list);
__reset_counters(pernet);
pernet->next_id = 1;
bitmap_zero(pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1);
bitmap_zero(pernet->id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
spin_unlock_bh(&pernet->lock);
mptcp_nl_flush_addrs_list(sock_net(skb->sk), &free_list);
synchronize_rcu();
Expand Down Expand Up @@ -1844,7 +1844,7 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info)
return ret;
}

int mptcp_pm_nl_dump_addr(struct mptcp_id_bitmap *bitmap,
int mptcp_pm_nl_dump_addr(unsigned long *bitmap,
const struct genl_info *info)
{
struct net *net = genl_info_net(info);
Expand All @@ -1853,7 +1853,7 @@ 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);
bitmap_copy(bitmap, pernet->id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
spin_unlock_bh(&pernet->lock);

return 0;
Expand All @@ -1862,17 +1862,17 @@ int mptcp_pm_nl_dump_addr(struct mptcp_id_bitmap *bitmap,
int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg,
struct netlink_callback *cb)
{
DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
const struct genl_info *info = genl_info_dump(cb);
struct mptcp_pm_addr_entry entry;
struct mptcp_id_bitmap id_bitmap;
int id = cb->args[0];
void *hdr;
int i;

mptcp_pm_dump_addr(&id_bitmap, info);
mptcp_pm_dump_addr(id_bitmap, info);

for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) {
if (test_bit(i, id_bitmap.map)) {
if (test_bit(i, id_bitmap)) {
if (mptcp_pm_get_addr(i, &entry, info))
break;

Expand Down
16 changes: 8 additions & 8 deletions net/mptcp/pm_userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *entry,
bool needs_id)
{
DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
struct mptcp_pm_addr_entry *match = NULL;
struct sock *sk = (struct sock *)msk;
struct mptcp_id_bitmap id_bitmap;
struct mptcp_pm_addr_entry *e;
bool addr_match = false;
bool id_match = false;
int ret = -EINVAL;

bitmap_zero(id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1);
bitmap_zero(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);

spin_lock_bh(&msk->pm.lock);
mptcp_for_each_userspace_pm_addr(msk, e) {
Expand All @@ -73,7 +73,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
} else if (addr_match || id_match) {
break;
}
__set_bit(e->addr.id, id_bitmap.map);
__set_bit(e->addr.id, id_bitmap);
}

if (!match && !addr_match && !id_match) {
Expand All @@ -88,7 +88,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,

*e = *entry;
if (!e->addr.id && needs_id)
e->addr.id = find_next_zero_bit(id_bitmap.map,
e->addr.id = find_next_zero_bit(id_bitmap,
MPTCP_PM_MAX_ADDR_ID + 1,
1);
list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list);
Expand Down Expand Up @@ -660,7 +660,7 @@ int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc,
}

static int mptcp_userspace_pm_set_bitmap(struct mptcp_sock *msk,
struct mptcp_id_bitmap *bitmap)
mptcp_pm_addr_id_bitmap_t *bitmap)
{
struct mptcp_pm_addr_entry *entry;

Expand All @@ -677,12 +677,12 @@ static int mptcp_userspace_pm_set_bitmap(struct mptcp_sock *msk,
}

static int userspace_pm_dump_addr(struct mptcp_sock *msk,
struct mptcp_id_bitmap *bitmap)
mptcp_pm_addr_id_bitmap_t *bitmap)
{
return mptcp_userspace_pm_set_bitmap(msk, bitmap);
}

int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap,
int mptcp_userspace_pm_dump_addr(unsigned long *bitmap,
const struct genl_info *info)
{
struct mptcp_sock *msk;
Expand All @@ -699,7 +699,7 @@ int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap,
spin_lock_bh(&msk->pm.lock);
ret = INDIRECT_CALL_1(msk->pm.ops->dump_addr,
userspace_pm_dump_addr,
msk, bitmap);
msk, (mptcp_pm_addr_id_bitmap_t *)bitmap);
spin_unlock_bh(&msk->pm.lock);
release_sock(sk);

Expand Down
Loading

0 comments on commit 722a742

Please sign in to comment.