Skip to content

Commit 6a52f0e

Browse files
committed
tgupdate: merge t/DO-NOT-MERGE-git-markup-features-other-trees base into t/DO-NOT-MERGE-git-markup-features-other-trees
2 parents e998ec5 + 0d94862 commit 6a52f0e

File tree

6 files changed

+72
-34
lines changed

6 files changed

+72
-34
lines changed

include/net/sock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,8 @@ static inline void sk_mem_uncharge(struct sock *sk, int size)
16311631
sk_mem_reclaim(sk);
16321632
}
16331633

1634+
void __sk_charge(struct sock *sk, gfp_t gfp);
1635+
16341636
#if IS_ENABLED(CONFIG_PROVE_LOCKING) && IS_ENABLED(CONFIG_MODULES)
16351637
static inline void sk_owner_set(struct sock *sk, struct module *owner)
16361638
{

net/core/sock.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3448,6 +3448,24 @@ void __sk_mem_reclaim(struct sock *sk, int amount)
34483448
}
34493449
EXPORT_SYMBOL(__sk_mem_reclaim);
34503450

3451+
void __sk_charge(struct sock *sk, gfp_t gfp)
3452+
{
3453+
int amt;
3454+
3455+
gfp |= __GFP_NOFAIL;
3456+
if (mem_cgroup_from_sk(sk)) {
3457+
/* The socket has not been accepted yet, no need
3458+
* to look at newsk->sk_wmem_queued.
3459+
*/
3460+
amt = sk_mem_pages(sk->sk_forward_alloc +
3461+
atomic_read(&sk->sk_rmem_alloc));
3462+
if (amt)
3463+
mem_cgroup_sk_charge(sk, amt, gfp);
3464+
}
3465+
3466+
kmem_cache_charge(sk, gfp);
3467+
}
3468+
34513469
int sk_set_peek_off(struct sock *sk, int val)
34523470
{
34533471
WRITE_ONCE(sk->sk_peek_off, val);

net/ipv4/af_inet.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -756,23 +756,8 @@ EXPORT_SYMBOL(inet_stream_connect);
756756
void __inet_accept(struct socket *sock, struct socket *newsock, struct sock *newsk)
757757
{
758758
if (mem_cgroup_sockets_enabled) {
759-
gfp_t gfp = GFP_KERNEL | __GFP_NOFAIL;
760-
761759
mem_cgroup_sk_alloc(newsk);
762-
763-
if (mem_cgroup_from_sk(newsk)) {
764-
int amt;
765-
766-
/* The socket has not been accepted yet, no need
767-
* to look at newsk->sk_wmem_queued.
768-
*/
769-
amt = sk_mem_pages(newsk->sk_forward_alloc +
770-
atomic_read(&newsk->sk_rmem_alloc));
771-
if (amt)
772-
mem_cgroup_sk_charge(newsk, amt, gfp);
773-
}
774-
775-
kmem_cache_charge(newsk, gfp);
760+
__sk_charge(newsk, GFP_KERNEL);
776761
}
777762

778763
sock_rps_record_flow(newsk);

net/mptcp/protocol.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,8 @@ static bool __mptcp_finish_join(struct mptcp_sock *msk, struct sock *ssk)
922922
mptcp_subflow_ctx(ssk)->subflow_id = msk->subflow_id++;
923923
mptcp_sockopt_sync_locked(msk, ssk);
924924
mptcp_stop_tout_timer(sk);
925+
__mptcp_inherit_cgrp_data(sk, ssk);
926+
__mptcp_inherit_memcg(sk, ssk, GFP_ATOMIC);
925927
__mptcp_propagate_sndbuf(sk, ssk);
926928
return true;
927929
}
@@ -4039,6 +4041,29 @@ static int mptcp_listen(struct socket *sock, int backlog)
40394041
return err;
40404042
}
40414043

4044+
static void mptcp_graph_subflows(struct sock *sk)
4045+
{
4046+
struct mptcp_subflow_context *subflow;
4047+
struct mptcp_sock *msk = mptcp_sk(sk);
4048+
4049+
mptcp_for_each_subflow(msk, subflow) {
4050+
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
4051+
bool slow;
4052+
4053+
slow = lock_sock_fast(ssk);
4054+
4055+
/* set ssk->sk_socket of accept()ed flows to mptcp socket.
4056+
* This is needed so NOSPACE flag can be set from tcp stack.
4057+
*/
4058+
if (!ssk->sk_socket)
4059+
mptcp_sock_graft(ssk, sk->sk_socket);
4060+
4061+
__mptcp_inherit_cgrp_data(sk, ssk);
4062+
__mptcp_inherit_memcg(sk, ssk, GFP_KERNEL);
4063+
unlock_sock_fast(ssk, slow);
4064+
}
4065+
}
4066+
40424067
static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
40434068
struct proto_accept_arg *arg)
40444069
{
@@ -4086,16 +4111,7 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
40864111
msk = mptcp_sk(newsk);
40874112
msk->in_accept_queue = 0;
40884113

4089-
/* set ssk->sk_socket of accept()ed flows to mptcp socket.
4090-
* This is needed so NOSPACE flag can be set from tcp stack.
4091-
*/
4092-
mptcp_for_each_subflow(msk, subflow) {
4093-
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
4094-
4095-
if (!ssk->sk_socket)
4096-
mptcp_sock_graft(ssk, newsock);
4097-
}
4098-
4114+
mptcp_graph_subflows(newsk);
40994115
mptcp_rps_record_subflows(msk);
41004116

41014117
/* Do late cleanup for the first subflow as necessary. Also

net/mptcp/protocol.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,9 @@ mptcp_subflow_delegated_next(struct mptcp_delegated_action *delegated)
749749
return ret;
750750
}
751751

752+
void __mptcp_inherit_memcg(struct sock *sk, struct sock *ssk, gfp_t gfp);
753+
void __mptcp_inherit_cgrp_data(struct sock *sk, struct sock *ssk);
754+
752755
int mptcp_is_enabled(const struct net *net);
753756
unsigned int mptcp_get_add_addr_timeout(const struct net *net);
754757
int mptcp_is_checksum_enabled(const struct net *net);

net/mptcp/subflow.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,21 +1720,35 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_local *local,
17201720
return err;
17211721
}
17221722

1723-
static void mptcp_attach_cgroup(struct sock *parent, struct sock *child)
1723+
void __mptcp_inherit_memcg(struct sock *sk, struct sock *ssk, gfp_t gfp)
1724+
{
1725+
/* Only if the msk has been accepted already (and not orphaned).*/
1726+
if (!mem_cgroup_sockets_enabled || !sk->sk_socket)
1727+
return;
1728+
1729+
mem_cgroup_sk_inherit(sk, ssk);
1730+
__sk_charge(ssk, gfp);
1731+
}
1732+
1733+
void __mptcp_inherit_cgrp_data(struct sock *sk, struct sock *ssk)
17241734
{
17251735
#ifdef CONFIG_SOCK_CGROUP_DATA
1726-
struct sock_cgroup_data *parent_skcd = &parent->sk_cgrp_data,
1727-
*child_skcd = &child->sk_cgrp_data;
1736+
struct sock_cgroup_data *sk_cd = &sk->sk_cgrp_data,
1737+
*ssk_cd = &ssk->sk_cgrp_data;
17281738

17291739
/* only the additional subflows created by kworkers have to be modified */
1730-
if (cgroup_id(sock_cgroup_ptr(parent_skcd)) !=
1731-
cgroup_id(sock_cgroup_ptr(child_skcd))) {
1732-
cgroup_sk_free(child_skcd);
1733-
*child_skcd = *parent_skcd;
1734-
cgroup_sk_clone(child_skcd);
1740+
if (cgroup_id(sock_cgroup_ptr(sk_cd)) !=
1741+
cgroup_id(sock_cgroup_ptr(ssk_cd))) {
1742+
cgroup_sk_free(ssk_cd);
1743+
*ssk_cd = *sk_cd;
1744+
cgroup_sk_clone(sk_cd);
17351745
}
17361746
#endif /* CONFIG_SOCK_CGROUP_DATA */
1747+
}
17371748

1749+
static void mptcp_attach_cgroup(struct sock *parent, struct sock *child)
1750+
{
1751+
__mptcp_inherit_cgrp_data(parent, child);
17381752
if (mem_cgroup_sockets_enabled)
17391753
mem_cgroup_sk_inherit(parent, child);
17401754
}

0 commit comments

Comments
 (0)