Commit e3859603 authored by Paolo Abeni's avatar Paolo Abeni Committed by David S. Miller

mptcp: better msk receive window updates

Move mptcp_cleanup_rbuf() related checks inside the mentioned
helper and extend them to mirror TCP checks more closely.

Additionally drop the 'rmem_pending' hack, since commit 87952603
("mptcp: protect the rx path with the msk socket spinlock") we
can use instead 'rmem_released'.

Fixes: ea4ca586 ("mptcp: refine MPTCP-level ack scheduling")
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d8b59efa
...@@ -498,8 +498,8 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb, ...@@ -498,8 +498,8 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
{ {
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk); struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
struct mptcp_sock *msk = mptcp_sk(subflow->conn); struct mptcp_sock *msk = mptcp_sk(subflow->conn);
u64 snd_data_fin_enable, ack_seq;
unsigned int dss_size = 0; unsigned int dss_size = 0;
u64 snd_data_fin_enable;
struct mptcp_ext *mpext; struct mptcp_ext *mpext;
unsigned int ack_size; unsigned int ack_size;
bool ret = false; bool ret = false;
...@@ -531,13 +531,14 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb, ...@@ -531,13 +531,14 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
return ret; return ret;
} }
ack_seq = READ_ONCE(msk->ack_seq);
if (READ_ONCE(msk->use_64bit_ack)) { if (READ_ONCE(msk->use_64bit_ack)) {
ack_size = TCPOLEN_MPTCP_DSS_ACK64; ack_size = TCPOLEN_MPTCP_DSS_ACK64;
opts->ext_copy.data_ack = READ_ONCE(msk->ack_seq); opts->ext_copy.data_ack = ack_seq;
opts->ext_copy.ack64 = 1; opts->ext_copy.ack64 = 1;
} else { } else {
ack_size = TCPOLEN_MPTCP_DSS_ACK32; ack_size = TCPOLEN_MPTCP_DSS_ACK32;
opts->ext_copy.data_ack32 = (uint32_t)READ_ONCE(msk->ack_seq); opts->ext_copy.data_ack32 = (uint32_t)ack_seq;
opts->ext_copy.ack64 = 0; opts->ext_copy.ack64 = 0;
} }
opts->ext_copy.use_ack = 1; opts->ext_copy.use_ack = 1;
......
...@@ -457,7 +457,18 @@ static bool mptcp_subflow_cleanup_rbuf(struct sock *ssk) ...@@ -457,7 +457,18 @@ static bool mptcp_subflow_cleanup_rbuf(struct sock *ssk)
static void mptcp_cleanup_rbuf(struct mptcp_sock *msk) static void mptcp_cleanup_rbuf(struct mptcp_sock *msk)
{ {
struct sock *ack_hint = READ_ONCE(msk->ack_hint); struct sock *ack_hint = READ_ONCE(msk->ack_hint);
int old_space = READ_ONCE(msk->old_wspace);
struct mptcp_subflow_context *subflow; struct mptcp_subflow_context *subflow;
struct sock *sk = (struct sock *)msk;
bool cleanup;
/* this is a simple superset of what tcp_cleanup_rbuf() implements
* so that we don't have to acquire the ssk socket lock most of the time
* to do actually nothing
*/
cleanup = __mptcp_space(sk) - old_space >= max(0, old_space);
if (!cleanup)
return;
/* if the hinted ssk is still active, try to use it */ /* if the hinted ssk is still active, try to use it */
if (likely(ack_hint)) { if (likely(ack_hint)) {
...@@ -1865,7 +1876,7 @@ static void __mptcp_splice_receive_queue(struct sock *sk) ...@@ -1865,7 +1876,7 @@ static void __mptcp_splice_receive_queue(struct sock *sk)
skb_queue_splice_tail_init(&sk->sk_receive_queue, &msk->receive_queue); skb_queue_splice_tail_init(&sk->sk_receive_queue, &msk->receive_queue);
} }
static bool __mptcp_move_skbs(struct mptcp_sock *msk, unsigned int rcv) static bool __mptcp_move_skbs(struct mptcp_sock *msk)
{ {
struct sock *sk = (struct sock *)msk; struct sock *sk = (struct sock *)msk;
unsigned int moved = 0; unsigned int moved = 0;
...@@ -1885,13 +1896,10 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk, unsigned int rcv) ...@@ -1885,13 +1896,10 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk, unsigned int rcv)
slowpath = lock_sock_fast(ssk); slowpath = lock_sock_fast(ssk);
mptcp_data_lock(sk); mptcp_data_lock(sk);
__mptcp_update_rmem(sk);
done = __mptcp_move_skbs_from_subflow(msk, ssk, &moved); done = __mptcp_move_skbs_from_subflow(msk, ssk, &moved);
mptcp_data_unlock(sk); mptcp_data_unlock(sk);
if (moved && rcv) { tcp_cleanup_rbuf(ssk, moved);
WRITE_ONCE(msk->rmem_pending, min(rcv, moved));
tcp_cleanup_rbuf(ssk, 1);
WRITE_ONCE(msk->rmem_pending, 0);
}
unlock_sock_fast(ssk, slowpath); unlock_sock_fast(ssk, slowpath);
} while (!done); } while (!done);
...@@ -1904,6 +1912,7 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk, unsigned int rcv) ...@@ -1904,6 +1912,7 @@ static bool __mptcp_move_skbs(struct mptcp_sock *msk, unsigned int rcv)
ret |= __mptcp_ofo_queue(msk); ret |= __mptcp_ofo_queue(msk);
__mptcp_splice_receive_queue(sk); __mptcp_splice_receive_queue(sk);
mptcp_data_unlock(sk); mptcp_data_unlock(sk);
mptcp_cleanup_rbuf(msk);
} }
if (ret) if (ret)
mptcp_check_data_fin((struct sock *)msk); mptcp_check_data_fin((struct sock *)msk);
...@@ -1933,7 +1942,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, ...@@ -1933,7 +1942,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
target = sock_rcvlowat(sk, flags & MSG_WAITALL, len); target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
while (copied < len) { while (copied < len) {
int bytes_read, old_space; int bytes_read;
bytes_read = __mptcp_recvmsg_mskq(msk, msg, len - copied); bytes_read = __mptcp_recvmsg_mskq(msk, msg, len - copied);
if (unlikely(bytes_read < 0)) { if (unlikely(bytes_read < 0)) {
...@@ -1944,14 +1953,11 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, ...@@ -1944,14 +1953,11 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
copied += bytes_read; copied += bytes_read;
if (skb_queue_empty(&msk->receive_queue) &&
__mptcp_move_skbs(msk, len - copied))
continue;
/* be sure to advertise window change */ /* be sure to advertise window change */
old_space = READ_ONCE(msk->old_wspace); mptcp_cleanup_rbuf(msk);
if ((tcp_space(sk) - old_space) >= old_space)
mptcp_cleanup_rbuf(msk); if (skb_queue_empty(&msk->receive_queue) && __mptcp_move_skbs(msk))
continue;
/* only the master socket status is relevant here. The exit /* only the master socket status is relevant here. The exit
* conditions mirror closely tcp_recvmsg() * conditions mirror closely tcp_recvmsg()
...@@ -1979,7 +1985,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, ...@@ -1979,7 +1985,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
/* race breaker: the shutdown could be after the /* race breaker: the shutdown could be after the
* previous receive queue check * previous receive queue check
*/ */
if (__mptcp_move_skbs(msk, len - copied)) if (__mptcp_move_skbs(msk))
continue; continue;
break; break;
} }
...@@ -2012,7 +2018,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, ...@@ -2012,7 +2018,7 @@ static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
/* .. race-breaker: ssk might have gotten new data /* .. race-breaker: ssk might have gotten new data
* after last __mptcp_move_skbs() returned false. * after last __mptcp_move_skbs() returned false.
*/ */
if (unlikely(__mptcp_move_skbs(msk, 0))) if (unlikely(__mptcp_move_skbs(msk)))
set_bit(MPTCP_DATA_READY, &msk->flags); set_bit(MPTCP_DATA_READY, &msk->flags);
} else if (unlikely(!test_bit(MPTCP_DATA_READY, &msk->flags))) { } else if (unlikely(!test_bit(MPTCP_DATA_READY, &msk->flags))) {
/* data to read but mptcp_wait_data() cleared DATA_READY */ /* data to read but mptcp_wait_data() cleared DATA_READY */
......
...@@ -234,7 +234,6 @@ struct mptcp_sock { ...@@ -234,7 +234,6 @@ struct mptcp_sock {
u64 wnd_end; u64 wnd_end;
unsigned long timer_ival; unsigned long timer_ival;
u32 token; u32 token;
int rmem_pending;
int rmem_released; int rmem_released;
unsigned long flags; unsigned long flags;
bool can_ack; bool can_ack;
...@@ -293,7 +292,7 @@ static inline struct mptcp_sock *mptcp_sk(const struct sock *sk) ...@@ -293,7 +292,7 @@ static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)
static inline int __mptcp_space(const struct sock *sk) static inline int __mptcp_space(const struct sock *sk)
{ {
return tcp_space(sk) + READ_ONCE(mptcp_sk(sk)->rmem_pending); return tcp_space(sk) + READ_ONCE(mptcp_sk(sk)->rmem_released);
} }
static inline struct mptcp_data_frag *mptcp_send_head(const struct sock *sk) static inline struct mptcp_data_frag *mptcp_send_head(const struct sock *sk)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment