Skip to content

Commit

Permalink
mptcp: drop mptcp_pm_get_* helpers
Browse files Browse the repository at this point in the history
Drop four mptcp_pm_get_* helpers:

	mptcp_pm_get_add_addr_signal_max();
	mptcp_pm_get_add_addr_accept_max();
	mptcp_pm_get_subflows_max();
	mptcp_pm_get_local_addr_max();

The helper pm_nl_get_pernet_from_msk() now can be used instead of using
each of them.

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
geliangtang authored and intel-lab-lkp committed Nov 4, 2023
1 parent bf21599 commit a6fa0e7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 54 deletions.
12 changes: 7 additions & 5 deletions net/mptcp/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void mptcp_pm_new_connection(struct mptcp_sock *msk, const struct sock *ssk, int

bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk)
{
struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
struct mptcp_pm_data *pm = &msk->pm;
unsigned int subflows_max;
int ret = 0;
Expand All @@ -99,7 +100,7 @@ bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk)
return false;
}

subflows_max = mptcp_pm_get_subflows_max(msk);
subflows_max = READ_ONCE(pernet->subflows_max);

pr_debug("msk=%p subflows=%d max=%d allow=%d", msk, pm->subflows,
subflows_max, READ_ONCE(pm->accept_subflow));
Expand Down Expand Up @@ -496,6 +497,7 @@ bool mptcp_pm_addr_families_match(const struct sock *sk,

void mptcp_pm_data_reset(struct mptcp_sock *msk)
{
struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
u8 pm_type = mptcp_get_pm_type(sock_net((struct sock *)msk));
struct mptcp_pm_data *pm = &msk->pm;

Expand All @@ -508,17 +510,17 @@ void mptcp_pm_data_reset(struct mptcp_sock *msk)
WRITE_ONCE(pm->pm_type, pm_type);

if (pm_type == MPTCP_PM_TYPE_KERNEL) {
bool subflows_allowed = !!mptcp_pm_get_subflows_max(msk);
bool subflows_allowed = !!READ_ONCE(pernet->subflows_max);

/* pm->work_pending must be only be set to 'true' when
* pm->pm_type is set to MPTCP_PM_TYPE_KERNEL
*/
WRITE_ONCE(pm->work_pending,
(!!mptcp_pm_get_local_addr_max(msk) &&
(!!READ_ONCE(pernet->local_addr_max) &&
subflows_allowed) ||
!!mptcp_pm_get_add_addr_signal_max(msk));
!!READ_ONCE(pernet->add_addr_signal_max));
WRITE_ONCE(pm->accept_addr,
!!mptcp_pm_get_add_addr_accept_max(msk) &&
!!READ_ONCE(pernet->add_addr_accept_max) &&
subflows_allowed);
WRITE_ONCE(pm->accept_subflow, subflows_allowed);
} else {
Expand Down
50 changes: 10 additions & 40 deletions net/mptcp/pm_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,43 +183,11 @@ select_signal_address(struct pm_nl_pernet *pernet, const struct mptcp_sock *msk)
return ret;
}

unsigned int mptcp_pm_get_add_addr_signal_max(const struct mptcp_sock *msk)
{
const struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);

return READ_ONCE(pernet->add_addr_signal_max);
}
EXPORT_SYMBOL_GPL(mptcp_pm_get_add_addr_signal_max);

unsigned int mptcp_pm_get_add_addr_accept_max(const struct mptcp_sock *msk)
{
struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);

return READ_ONCE(pernet->add_addr_accept_max);
}
EXPORT_SYMBOL_GPL(mptcp_pm_get_add_addr_accept_max);

unsigned int mptcp_pm_get_subflows_max(const struct mptcp_sock *msk)
{
struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);

return READ_ONCE(pernet->subflows_max);
}
EXPORT_SYMBOL_GPL(mptcp_pm_get_subflows_max);

unsigned int mptcp_pm_get_local_addr_max(const struct mptcp_sock *msk)
{
struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);

return READ_ONCE(pernet->local_addr_max);
}
EXPORT_SYMBOL_GPL(mptcp_pm_get_local_addr_max);

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) ||
if (msk->pm.subflows == READ_ONCE(pernet->subflows_max) ||
(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);
Expand Down Expand Up @@ -404,14 +372,15 @@ static unsigned int fill_remote_addresses_vec(struct mptcp_sock *msk,
bool fullmesh,
struct mptcp_addr_info *addrs)
{
struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
bool deny_id0 = READ_ONCE(msk->pm.remote_deny_join_id0);
struct sock *sk = (struct sock *)msk, *ssk;
struct mptcp_subflow_context *subflow;
struct mptcp_addr_info remote = { 0 };
unsigned int subflows_max;
int i = 0;

subflows_max = mptcp_pm_get_subflows_max(msk);
subflows_max = READ_ONCE(pernet->subflows_max);
remote_address((struct sock_common *)sk, &remote);

/* Non-fullmesh endpoint, fill in the single entry
Expand Down Expand Up @@ -514,9 +483,9 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)

pernet = pm_nl_get_pernet(sock_net(sk));

add_addr_signal_max = mptcp_pm_get_add_addr_signal_max(msk);
local_addr_max = mptcp_pm_get_local_addr_max(msk);
subflows_max = mptcp_pm_get_subflows_max(msk);
add_addr_signal_max = READ_ONCE(pernet->add_addr_signal_max);
local_addr_max = READ_ONCE(pernet->local_addr_max);
subflows_max = READ_ONCE(pernet->subflows_max);

/* do lazy endpoint usage accounting for the MPC subflows */
if (unlikely(!(msk->pm.status & BIT(MPTCP_PM_MPC_ENDPOINT_ACCOUNTED))) && msk->first) {
Expand Down Expand Up @@ -621,7 +590,7 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,
int i = 0;

pernet = pm_nl_get_pernet_from_msk(msk);
subflows_max = mptcp_pm_get_subflows_max(msk);
subflows_max = READ_ONCE(pernet->subflows_max);

rcu_read_lock();
list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
Expand Down Expand Up @@ -664,15 +633,16 @@ static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,

static void mptcp_pm_nl_add_addr_received(struct mptcp_sock *msk)
{
struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
struct mptcp_addr_info addrs[MPTCP_PM_ADDR_MAX];
struct sock *sk = (struct sock *)msk;
unsigned int add_addr_accept_max;
struct mptcp_addr_info remote;
unsigned int subflows_max;
int i, nr;

add_addr_accept_max = mptcp_pm_get_add_addr_accept_max(msk);
subflows_max = mptcp_pm_get_subflows_max(msk);
add_addr_accept_max = READ_ONCE(pernet->add_addr_accept_max);
subflows_max = READ_ONCE(pernet->subflows_max);

pr_debug("accepted %d:%d remote family %d",
msk->pm.add_addr_accepted, add_addr_accept_max,
Expand Down
8 changes: 3 additions & 5 deletions net/mptcp/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -1046,15 +1046,13 @@ struct pm_nl_pernet {

struct pm_nl_pernet *
pm_nl_get_pernet_from_msk(const 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);
unsigned int mptcp_pm_get_subflows_max(const struct mptcp_sock *msk);
unsigned int mptcp_pm_get_local_addr_max(const struct mptcp_sock *msk);

/* called under PM lock */
static inline void __mptcp_pm_close_subflow(struct mptcp_sock *msk)
{
if (--msk->pm.subflows < mptcp_pm_get_subflows_max(msk))
struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);

if (--msk->pm.subflows < READ_ONCE(pernet->subflows_max))
WRITE_ONCE(msk->pm.accept_subflow, true);
}

Expand Down
9 changes: 5 additions & 4 deletions net/mptcp/sockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,7 @@ static int mptcp_getsockopt_first_sf_only(struct mptcp_sock *msk, int level, int

void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
{
struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
struct sock *sk = (struct sock *)msk;
u32 flags = 0;
bool slow;
Expand All @@ -907,13 +908,13 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
/* The following limits only make sense for the in-kernel PM */
if (mptcp_pm_is_kernel(msk)) {
info->mptcpi_subflows_max =
mptcp_pm_get_subflows_max(msk);
READ_ONCE(pernet->subflows_max);
info->mptcpi_add_addr_signal_max =
mptcp_pm_get_add_addr_signal_max(msk);
READ_ONCE(pernet->add_addr_signal_max);
info->mptcpi_add_addr_accepted_max =
mptcp_pm_get_add_addr_accept_max(msk);
READ_ONCE(pernet->add_addr_accept_max);
info->mptcpi_local_addr_max =
mptcp_pm_get_local_addr_max(msk);
READ_ONCE(pernet->local_addr_max);
}

if (__mptcp_check_fallback(msk))
Expand Down

0 comments on commit a6fa0e7

Please sign in to comment.