net/smc: fix panic smc_tcp_syn_recv_sock() while closing listen socket
Subsystems (5)
D. Wythe
maintainerPATCH 1/1 net/smc: fix panic smc_tcp_syn_recv_sock() while closing listen socket
From: "D. Wythe" <[email protected]>
Consider the following scenarios:
smc_release
smc_close_active write_lock_bh(&smc->clcsock->sk->sk_callback_lock); smc->clcsock->sk->sk_user_data = NULL; write_unlock_bh(&smc->clcsock->sk->sk_callback_lock);
smc_tcp_syn_recv_sock
smc = smc_clcsock_user_data(sk); /* now */ /* smc == NULL */
Hence, we may read the a NULL value in smc_tcp_syn_recv_sock(). And since we only unset sk_user_data during smc_release, it's safe to drop the incoming tcp reqsock.
--- net/smc/af_smc.c | 2 ++ 1 file changed, 2 insertions(+)
net/smc/af_smc.c +2 -0
@@ -125,6 +125,8 @@ static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk,struct sock *child; smc =smc_clcsock_user_data (sk); +if (unlikely (!smc)) + goto drop;if (READ_ONCE (sk->sk_ack_backlog) +atomic_read (&smc->queued_smc_hs) > sk->sk_max_ack_backlog)
Signature · 1 line
1.8.3.1
Dust Li
maintainerQuoted 30 lines · D. Wythe
From: "D. Wythe" <[email protected]>
Consider the following scenarios:
smc_releasesmc_close_active write_lock_bh(&smc->clcsock->sk->sk_callback_lock); smc->clcsock->sk->sk_user_data = NULL; write_unlock_bh(&smc->clcsock->sk->sk_callback_lock);
smc_tcp_syn_recv_socksmc = smc_clcsock_user_data(sk); /* now */ /* smc == NULL */Hence, we may read the a NULL value in
smc_tcp_syn_recv_sock(). And since we only unsetsk_user_dataduringsmc_release, it's safe to drop the incoming tcp reqsock.Fixes ("net/smc: net/smc: Limit backlog connections"Signed-off-by D. Wythe <[email protected]>---
net/smc/af_smc.c| 2 ++1 file changed, 2 insertions(+)net/smc/af_smc.c +0
-0
net/smc/af_smc.c static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk, · line 129
Quoted 5 lines
net/smc/af_smc.c +2
-0@@ -125,6 +125,8 @@ static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk,struct sock *child; smc =smc_clcsock_user_data (sk); +if (unlikely (!smc)) + goto drop;
Is it possible smc != NULL here
net/smc/af_smc.c static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk, · line 131
Quoted 2 lines
net/smc/af_smc.c +0
-0if (READ_ONCE(sk->sk_ack_backlog) + atomic_read(&smc->queued_smc_hs) >
But later turns to NULL in 'atomic_read(&smc->queue_smc_hs)'
net/smc/af_smc.c static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk, · line 132
Quoted 1 line
net/smc/af_smc.c +0
-0sk->sk_max_ack_backlog)
Seems there is still a race ?
Quoted 2 lines
Signature · 1 line
1.8.3.1
Simon Horman
reviewerQuoted 15 lines · D. Wythe
From: "D. Wythe" <[email protected]>
Consider the following scenarios:
smc_releasesmc_close_active write_lock_bh(&smc->clcsock->sk->sk_callback_lock); smc->clcsock->sk->sk_user_data = NULL; write_unlock_bh(&smc->clcsock->sk->sk_callback_lock);
smc_tcp_syn_recv_socksmc = smc_clcsock_user_data(sk); /* now */ /* smc == NULL */
Quoted 5 lines
Hence, we may read the a NULL value in
smc_tcp_syn_recv_sock(). And since we only unsetsk_user_dataduringsmc_release, it's safe to drop the incoming tcp reqsock.Fixes ("net/smc: net/smc: Limit backlog connections"
The tag above is malformed. The correct form is:
Quoted 22 lines
Signed-off-by D. Wythe <[email protected]>--- net/smc/af_smc.c | 2 ++ 1 file changed, 2 insertions(+)net/smc/af_smc.c +2
-0@@ -125,6 +125,8 @@ static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk,struct sock *child; smc =smc_clcsock_user_data (sk); +if (unlikely (!smc)) + goto drop;if (READ_ONCE (sk->sk_ack_backlog) +atomic_read (&smc->queued_smc_hs) > sk->sk_max_ack_backlog)Signature · 1 line
1.8.3.1
Quoted 30 lines · D. Wythe
From: "D. Wythe" <[email protected]>
Consider the following scenarios:
smc_releasesmc_close_active write_lock_bh(&smc->clcsock->sk->sk_callback_lock); smc->clcsock->sk->sk_user_data = NULL; write_unlock_bh(&smc->clcsock->sk->sk_callback_lock);
smc_tcp_syn_recv_socksmc = smc_clcsock_user_data(sk); /* now */ /* smc == NULL */Hence, we may read the a NULL value in
smc_tcp_syn_recv_sock(). And since we only unsetsk_user_dataduringsmc_release, it's safe to drop the incoming tcp reqsock.Fixes ("net/smc: net/smc: Limit backlog connections"Signed-off-by D. Wythe <[email protected]>--- net/smc/af_smc.c | 2 ++ 1 file changed, 2 insertions(+)net/smc/af_smc.c +0
-0
net/smc/af_smc.c static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk, · line 132
Quoted 8 lines
net/smc/af_smc.c +2
-0@@ -125,6 +125,8 @@ static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk,struct sock *child; smc =smc_clcsock_user_data (sk); +if (unlikely (!smc)) + goto drop;if (READ_ONCE (sk->sk_ack_backlog) +atomic_read (&smc->queued_smc_hs) > sk->sk_max_ack_backlog)
Hi D.Wythe,
this is unfortunately not sufficient for this fix. You have to make sure that is not a life-time problem. Even so, READ_ONCE() is also needed in this case.
Thanks,
Wenjia
D. Wythe
maintainerQuoted 28 lines · Wenjia Zhang
Quoted 25 lines · D. Wythe
From: "D. Wythe" <[email protected]>
Consider the following scenarios:
smc_release
smc_close_activewrite_lock_bh(&smc->clcsock->sk->sk_callback_lock);smc->clcsock->sk->sk_user_data= NULL;write_unlock_bh(&smc->clcsock->sk->sk_callback_lock);
smc_tcp_syn_recv_sock
smc =smc_clcsock_user_data(sk);
/* now */
/* smc == NULL */Hence, we may read the a NULL value in
smc_tcp_syn_recv_sock(). And since we only unsetsk_user_dataduringsmc_release, it's safe to drop the incoming tcp reqsock.Fixes ("net/smc: net/smc: Limit backlog connections"Signed-off-by D. Wythe <[email protected]>---
net/smc/af_smc.c| 2 ++1 file changed, 2 insertions(+)
Quoted 12 lines
Quoted 10 lines
net/smc/af_smc.c +2
-0@@ -125,6 +125,8 @@ static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk, struct sock *child; smc = smc_clcsock_user_data(sk); + if (unlikely(!smc)) + goto drop;Quoted 2 lines
if (
READ_ONCE(sk->sk_ack_backlog)+atomic_read(&smc->queued_smc_hs)>sk->sk_max_ack_backlog)
Hi Wenjia,
Quoted 3 lines
this is unfortunately not sufficient for this fix. You have to make sure that is not a life-time problem. Even so,
READ_ONCE()is also needed in this case.
Life-time problem? If you means the smc will still be NULL in the future, I don't really think so, smc is a local variable assigned by smc_clcsock_user_data. it's either NULL or a valid and unchanged value.
And READ_ONCE() is needed indeed, considering not make too much change, maybe we can protected following
smc = smc_clcsock_user_data(sk);
with sk_callback_lock, which solves the same problem. What do you think?
Best Wishes
D. Wythe
Quoted 10 lines · D. Wythe
Hi Wenjia,
Quoted 3 lines
this is unfortunately not sufficient for this fix. You have to make sure that is not a life-time problem. Even so,
READ_ONCE()is also needed in this case.Life-time problem? If you means the smc will still be NULL in the future, I don't really think so, smc is a local variable assigned by
smc_clcsock_user_data. it's either NULL or a valid and unchanged value.And
READ_ONCE()is needed indeed, considering not make too much change, maybe we can protected following
The local variable smc is a pointer to the smc_sock structure, so the question is whether you can just do a READ_ONCE and then continue to use the content of the smc_sock structure, even though e.g. a smc_close_active() may be going on in parallel.
Quoted 4 lines
smc =
smc_clcsock_user_data(sk);with sk_callback_lock, which solves the same problem. What do you think?
In af_ops.syn_recv_sock() and thus also in smc_tcp_syn_recv_sock()
sk is defined as const. So you cannot simply do take sk_callback_lock, that will create compiler errors.
(same for smc_hs_congested() BTW)
If you are sure the contents of *smc are always valid, then READ_ONCE is all you need.
Maybe it is better to take a step back and consider what needs to be protected when (lifetime).
Just some thoughts (there may be ramifications that I am not aware of):
Maybe clcsock->sk->sk_user_data could be set to point to smc_sock as soon as the clc socket is created? Isn't the smc socket always valid as long as the clc socket exists?
Then sk_user_data would no longer indicate whether the callback functions were set to smc values, but would that matter? Are there scenarios where it matters whether the old or the new callback function is called?
Why are the values restored in smc_close_active() if the clc socket is released shortly after anyhow?
You see I am wondering whether adding more locking, there is a way to make sure structures are safe to use.
D. Wythe
maintainerQuoted 13 lines · Alexandra Winter
Quoted 8 lines · D. Wythe
Hi Wenjia,
Quoted 2 lines
this is unfortunately not sufficient for this fix. You have to make sure that is not a life-time problem. Even so,
READ_ONCE()is also needed in this case.Life-time problem? If you means the smc will still be NULL in the future, I don't really think so, smc is a local variable assigned by
smc_clcsock_user_data. it's either NULL or a valid and unchanged value.And
READ_ONCE()is needed indeed, considering not make too much change, maybe we can protected followingThe local variable smc is a pointer to the
smc_sockstructure, so the question is whether you can just do aREAD_ONCEand then continue to use the content of thesmc_sockstructure, even though e.g. asmc_close_active()may be going on in parallel.
Quoted 8 lines
Quoted 3 lines
smc =
smc_clcsock_user_data(sk);with sk_callback_lock, which solves the same problem. What do you think?
In
af_ops.syn_recv_sock()and thus also insmc_tcp_syn_recv_sock()
sk is defined as const. So you cannot simply do takesk_callback_lock, that will create compiler errors.
(same forsmc_hs_congested()BTW)If you are sure the contents of *smc are always valid, then
READ_ONCEis all you need.
Hi Alexandra,
You are right. The key point is how to ensure the valid of smc sock during the life time of clc sock, If so, READ_ONCE is good enough. Unfortunately, I found that there are no such guarantee, so it's still a life-time problem. Considering the const, maybe we need to do :
1. hold a refcnt of smc_sock for syn_recv_sock to keep smc sock valid during life time of clc sock
2. put the refcnt of smc_sock in sk_destruct in tcp_sock to release the very smc sock .
In that way, we can always make sure the valid of smc sock during the life time of clc sock. Then we can use READ_ONCE rather than lock. What do you think ?
Quoted 7 lines
Maybe it is better to take a step back and consider what needs to be protected when (lifetime).
Just some thoughts (there may be ramifications that I am not aware of):
Maybeclcsock->sk->sk_user_datacould be set to point tosmc_sockas soon as the clc socket is created? Isn't the smc socket always valid as long as the clc socket exists?
Thensk_user_datawould no longer indicate whether the callback functions were set to smc values, but would that matter? Are there scenarios where it matters whether the old or the new callback function is called?
Why are the values restored insmc_close_active()if the clc socket is released shortly after anyhow?
That's a good question, We have discussed internally and found that this is indeed possible. We can completely not to unset sk_user_data, which can reduce many unnecessary judgments and locks, and no side effects found. We will try this approach internally and conduct multiple rounds of testing. However, in any case, returning to the initial issue, the prerequisite for everything is to ensure the valid of smc sock during the life time of clc sock. So we must have a mechanism to work it out. and holding referenced solutions might be a good try, what do you think?
Best Wishes,
D. Wythe
Quoted 2 lines · D. Wythe
You are right. The key point is how to ensure the valid of smc sock during the life time of clc sock, If so,
READ_ONCEis good enough. Unfortunately, I found that there are no such guarantee, so it's still a life-time problem.
Did you discover a scenario, where clc sock could live longer than smc sock?
Wouldn't that be a dangerous scenario in itself? I still have some hope that the lifetime of an smc socket is by design longer than that of the corresponding tcp socket.
Considering the const, maybe
Quoted 7 lines
we need to do :
1. hold a refcnt of
smc_sockforsyn_recv_sockto keep smc sock valid during life time of clc sock
2. put the refcnt ofsmc_sockinsk_destructintcp_sockto release the very smc sock .In that way, we can always make sure the valid of smc sock during the life time of clc sock. Then we can use
READ_ONCErather than lock. What do you think ?
I am not sure I fully understand the details what you propose to do. And it is not only syn_recv_sock(), right?
You need to consider all relations between smc socks and tcp socks; fallback to tcp, initial creation, children of listen sockets, variants of shutdown, ... Preferrably a single simple mechanism covers all situations. Maybe there is such a mechanism already today? (I don't think clcsock->sk->sk_user_data or sk_callback_lock provide this general coverage)
If we really have a gap, a general refcnt'ing on smc sock could be a solution, but needs to be designed carefully.
Many thanks to you and the team to help make smc more stable and robust.
D. Wythe
maintainerQuoted 7 lines · Alexandra Winter
Quoted 2 lines · D. Wythe
You are right. The key point is how to ensure the valid of smc sock during the life time of clc sock, If so,
READ_ONCEis good enough. Unfortunately, I found that there are no such guarantee, so it's still a life-time problem.Did you discover a scenario, where clc sock could live longer than smc sock?
Wouldn't that be a dangerous scenario in itself? I still have some hope that the lifetime of an smc socket is by design longer than that of the corresponding tcp socket.
Hi Alexandra,
Yes there is. Considering scenario:
tcp_v4_rcv(skb)
/* req sock */
reqsk = _inet_lookup_skb(skb)
/* listen sock */
sk = reqsk(reqsk)->rsk_listener;sock_hold(sk);tcp_check_req(sk)
smc_release /* release smc listen sock */ __smc_release smc_close_active() /* smc_sk->sk_state = SMC_CLOSED; */
if (smc_sk->sk_state == SMC_CLOSED) smc_clcsock_release();
sock_release(clcsk); /* close clcsock */
sock_put(sk); /* might not the final refcnt */
sock_put(smc_sk) /* might be the final refcnt of smc_sock */
syn_recv_sock(sk...)
/* might be the final refcnt of tcp listen sock */ sock_put(sk);
Fortunately, this scenario only affects smc_syn_recv_sock and smc_hs_congested, as other callbacks already have locks to protect smc, which can guarantee that the sk_user_data is either NULL (set in smc_close_active) or valid under the lock.
Quoted 6 lines
Considering the const, maybe
Quoted 5 lines
we need to do :
1. hold a refcnt of
smc_sockforsyn_recv_sockto keep smc sock valid during life time of clc sock
2. put the refcnt ofsmc_sockinsk_destructintcp_sockto release the very smc sock .
Quoted 6 lines
Quoted 2 lines
In that way, we can always make sure the valid of smc sock during the life time of clc sock. Then we can use
READ_ONCErather than lock. What do you think ?I am not sure I fully understand the details what you propose to do. And it is not only
syn_recv_sock(), right?
You need to consider all relations between smc socks and tcp socks; fallback to tcp, initial creation, children of listen sockets, variants of shutdown, ... Preferrably a single simple mechanism covers all situations. Maybe there is such a mechanism already today? (I don't thinkclcsock->sk->sk_user_dataorsk_callback_lockprovide this general coverage)
If we really have a gap, a general refcnt'ing on smc sock could be a solution, but needs to be designed carefully.
You are right , we need designed it with care, we will try the referenced solutions internally first, and I will also send some RFCs so that everyone can track the latest progress and make it can be all agreed.
Quoted 1 line
Many thanks to you and the team to help make smc more stable and robust.
Our pleasure 😁. The stability of smc is important to us too.
Best wishes,
D. Wythe
Quoted 13 lines · D. Wythe
Quoted 6 lines
Considering the const, maybe
Quoted 5 lines
we need to do :
1. hold a refcnt of
smc_sockforsyn_recv_sockto keep smc sock valid during life time of clc sock
2. put the refcnt ofsmc_sockinsk_destructintcp_sockto release the very smc sock .Quoted 6 lines
Quoted 2 lines
In that way, we can always make sure the valid of smc sock during the life time of clc sock. Then we can use
READ_ONCErather than lock. What do you think ?I am not sure I fully understand the details what you propose to do. And it is not only
syn_recv_sock(), right?
You need to consider all relations between smc socks and tcp socks; fallback to tcp, initial creation, children of listen sockets, variants of shutdown, ... Preferrably a single simple mechanism covers all situations. Maybe there is such a mechanism already today? (I don't thinkclcsock->sk->sk_user_dataorsk_callback_lockprovide this general coverage)
If we really have a gap, a general refcnt'ing on smc sock could be a solution, but needs to be designed carefully.
Quoted 8 lines
You are right , we need designed it with care, we will try the referenced solutions internally first, and I will also send some RFCs so that everyone can track the latest progress and make it can be all agreed.
Quoted 1 line
Many thanks to you and the team to help make smc more stable and robust.
Our pleasure 😁. The stability of smc is important to us too.
Best wishes,
D. Wythe
Just one more thought: I noticed that9744d2bf1976 ("smc: Fix use-after-free in tcp_write_timer_handler().") states that unlike MPTCP, smc_clcsock_release() does not call __tcp_close(). (which matches your explanation).
Maybe we something similar to the MPTCP approach could also solve this issue?
Quoted 39 lines · D. Wythe
Quoted 7 lines · Alexandra Winter
Quoted 2 lines · D. Wythe
You are right. The key point is how to ensure the valid of smc sock during the life time of clc sock, If so,
READ_ONCEis good enough. Unfortunately, I found that there are no such guarantee, so it's still a life-time problem.Did you discover a scenario, where clc sock could live longer than smc sock?
Wouldn't that be a dangerous scenario in itself? I still have some hope that the lifetime of an smc socket is by design longer than that of the corresponding tcp socket.Hi Alexandra,
Yes there is. Considering scenario:
tcp_v4_rcv(skb)/* req sock */
reqsk =_inet_lookup_skb(skb)/* listen sock */
sk = reqsk(reqsk)->rsk_listener;sock_hold(sk);tcp_check_req(sk)
smc_release/* release
smc listen sock */
__smc_release
smc_close_active() /*smc_sk->sk_state=SMC_CLOSED; */
if
(smc_sk->sk_state==SMC_CLOSED)smc_clcsock_release();
sock_release(clcsk); /* close clcsock */
sock_put(sk); /* might not the final refcnt */sock_put(smc_sk) /* might be the final refcnt of smc_sock */
Quoted 7 lines
syn_recv_sock(sk...)
/* might be the final refcnt of tcp listen sock */sock_put(sk);Fortunately, this scenario only affects
smc_syn_recv_sockandsmc_hs_congested, as other callbacks already have locks to protect smc, which can guarantee that thesk_user_datais either NULL (set insmc_close_active) or valid under the lock.
I'm kind of confused with this scenario. How could the
smc_clcsock_release()->sock_release(clcsk) happen?
Because the syn_recv_sock happens short prior to accept(), that means that the &smc->tcp_listen_work is already triggered but the real accept() is still not happening. At this moment, the incoming connection is being added into the accept queue. Thus, if the sk->sk_state is changed from SMC_LISTEN to SMC_CLOSED in smc_close_active(), there is still "flush_work(&smc->tcp_listen_work);" after that. That ensures the smc_clcsock_release() should not happen, if smc_clcsock_accept() is not finished. Do you think that the execution of the &smc->tcp_listen_work is already done? Or am I missing something?
Quoted 23 lines
Quoted 6 lines
Considering the const, maybe
Quoted 5 lines
we need to do :
1. hold a refcnt of
smc_sockforsyn_recv_sockto keep smc sock valid during life time of clc sock
2. put the refcnt ofsmc_sockinsk_destructintcp_sockto release the very smc sock .Quoted 6 lines
Quoted 2 lines
In that way, we can always make sure the valid of smc sock during the life time of clc sock. Then we can use
READ_ONCErather than lock. What do you think ?I am not sure I fully understand the details what you propose to do. And it is not only
syn_recv_sock(), right?
You need to consider all relations between smc socks and tcp socks; fallback to tcp, initial creation, children of listen sockets, variants of shutdown, ... Preferrably a single simple mechanism covers all situations. Maybe there is such a mechanism already today? (I don't thinkclcsock->sk->sk_user_dataorsk_callback_lockprovide this general coverage)
If we really have a gap, a general refcnt'ing on smc sock could be a solution, but needs to be designed carefully.You are right , we need designed it with care, we will try the referenced solutions internally first, and I will also send some RFCs so that everyone can track the latest progress and make it can be all agreed.
Quoted 1 line
Many thanks to you and the team to help make smc more stable and robust.
Our pleasure 😁. The stability of smc is important to us too.
Best wishes,
D. Wythe
D. Wythe
maintainerQuoted 44 lines · Wenjia Zhang
Quoted 41 lines · D. Wythe
Quoted 7 lines · Alexandra Winter
Quoted 2 lines · D. Wythe
You are right. The key point is how to ensure the valid of smc sock during the life time of clc sock, If so,
READ_ONCEis good enough. Unfortunately, I found that there are no such guarantee, so it's still a life-time problem.Did you discover a scenario, where clc sock could live longer than smc sock?
Wouldn't that be a dangerous scenario in itself? I still have some hope that the lifetime of an smc socket is by design longer than that of the corresponding tcp socket.Hi Alexandra,
Yes there is. Considering scenario:
tcp_v4_rcv(skb)/* req sock */
reqsk =_inet_lookup_skb(skb)/* listen sock */
sk = reqsk(reqsk)->rsk_listener;sock_hold(sk);tcp_check_req(sk)
smc_release/* release smc listen sock */__smc_releasesmc_close_active() /*smc_sk->sk_state=SMC_CLOSED; */
if (smc_sk->sk_state==SMC_CLOSED)smc_clcsock_release();
sock_release(clcsk); /* close clcsock */
sock_put(sk); /* might not the final refcnt */sock_put(smc_sk) /* might be the final refcnt of smc_sock */
syn_recv_sock(sk...)
/* might be the final refcnt of tcp listen sock */sock_put(sk);
Quoted 6 lines
Quoted 3 lines
Fortunately, this scenario only affects
smc_syn_recv_sockandsmc_hs_congested, as other callbacks already have locks to protect smc, which can guarantee that thesk_user_datais either NULL (set insmc_close_active) or valid under the lock.
I'm kind of confused with this scenario. How could thesmc_clcsock_release()->sock_release(clcsk) happen?
Because thesyn_recv_sockhappens short prior toaccept(), that means that the&smc->tcp_listen_workis already triggered but the realaccept()is still not happening. At this moment, the incoming connection is being added into the accept queue. Thus, if thesk->sk_stateis changed fromSMC_LISTENtoSMC_CLOSEDinsmc_close_active(), there is still "flush_work(&smc->tcp_listen_work);" after that. That ensures thesmc_clcsock_release()should not happen, ifsmc_clcsock_accept()is not finished. Do you think that the execution of the&smc->tcp_listen_workis already done? Or am I missing something?
Hi wenjia,
Sorry for late reply, we have just returned from vacation.
The smc_clcsock_release here release the listen clcsock rather than the child clcsock. So the flush_work might not be helpful for this scenario.
Best wishes,
D. Wythe
Quoted 23 lines
Quoted 23 lines
Quoted 6 lines
Considering the const, maybe
Quoted 5 lines
we need to do :
1. hold a refcnt of
smc_sockforsyn_recv_sockto keep smc sock valid during life time of clc sock
2. put the refcnt ofsmc_sockinsk_destructintcp_sockto release the very smc sock .Quoted 6 lines
Quoted 2 lines
In that way, we can always make sure the valid of smc sock during the life time of clc sock. Then we can use
READ_ONCErather than lock. What do you think ?I am not sure I fully understand the details what you propose to do. And it is not only
syn_recv_sock(), right?
You need to consider all relations between smc socks and tcp socks; fallback to tcp, initial creation, children of listen sockets, variants of shutdown, ... Preferrably a single simple mechanism covers all situations. Maybe there is such a mechanism already today? (I don't thinkclcsock->sk->sk_user_dataorsk_callback_lockprovide this general coverage)
If we really have a gap, a general refcnt'ing on smc sock could be a solution, but needs to be designed carefully.You are right , we need designed it with care, we will try the referenced solutions internally first, and I will also send some RFCs so that everyone can track the latest progress and make it can be all agreed.
Quoted 1 line
Many thanks to you and the team to help make smc more stable and robust.
Our pleasure 😁. The stability of smc is important to us too.
Best wishes,
D. Wythe
Quoted 51 lines · Wenjia Zhang
Quoted 44 lines · D. Wythe
Quoted 41 lines · Alexandra Winter
Quoted 7 lines · D. Wythe
Quoted 2 lines
You are right. The key point is how to ensure the valid of smc sock during the life time of clc sock, If so,
READ_ONCEis good enough. Unfortunately, I found that there are no such guarantee, so it's still a life-time problem.Did you discover a scenario, where clc sock could live longer than smc sock?
Wouldn't that be a dangerous scenario in itself? I still have some hope that the lifetime of an smc socket is by design longer than that of the corresponding tcp socket.Hi Alexandra,
Yes there is. Considering scenario:
tcp_v4_rcv(skb)/* req sock */
reqsk =_inet_lookup_skb(skb)/* listen sock */
sk = reqsk(reqsk)->rsk_listener;sock_hold(sk);tcp_check_req(sk)
smc_release/* release smc listen sock */__smc_releasesmc_close_active() /*smc_sk->sk_state=SMC_CLOSED; */
if (smc_sk->sk_state==SMC_CLOSED)smc_clcsock_release();
sock_release(clcsk); /* close clcsock */
sock_put(sk); /* might not the final refcnt */sock_put(smc_sk) /* might be the final refcnt of smc_sock */
syn_recv_sock(sk...)
/* might be the final refcnt of tcp listen sock */sock_put(sk);Quoted 6 lines
Quoted 3 lines
Fortunately, this scenario only affects
smc_syn_recv_sockandsmc_hs_congested, as other callbacks already have locks to protect smc, which can guarantee that thesk_user_datais either NULL (set insmc_close_active) or valid under the lock.
I'm kind of confused with this scenario. How could thesmc_clcsock_release()->sock_release(clcsk) happen?
Because thesyn_recv_sockhappens short prior toaccept(), that means that the&smc->tcp_listen_workis already triggered but the realaccept()is still not happening. At this moment, the incoming connection is being added into the accept queue. Thus, if thesk->sk_stateis changed fromSMC_LISTENtoSMC_CLOSEDinsmc_close_active(), there is still "flush_work(&smc->tcp_listen_work);" after that. That ensures thesmc_clcsock_release()should not happen, ifsmc_clcsock_accept()is not finished. Do you think that the execution of the&smc->tcp_listen_workis already done? Or am I missing something?Quoted 1 line
Hi wenjia,
Quoted 8 lines
Sorry for late reply, we have just returned from vacation.
The
smc_clcsock_releasehere release the listen clcsock rather than the child clcsock.
So theflush_workmight not be helpful for this scenario.Best wishes,
D. Wythe
It seems like that I lost some mails these days :-( Just saw your answer.
Maybe I didn't describe my thought clearly. Following data flow is your scenario, right?
–
(sk_state == SMC_LISTEN)|tcp_check_req() | smc_release()
| ->__smc_release() | -> smc_close_active() | -> sk->sk_state = SMC_CLOSED; | -> ... | -> smc->clcsock->sk->sk_user_data = NULL; | -> ... |*1) -> flush_work(&smc->tcp_listen_work); |*4) | -> smc_clcsock_accept() | -> kernel_accept() | -> inet_csk_accept() |*5) | if (sk->sk_state == SMC_CLOSED) |*3)-> smc_clcsock_release() -> syn_recv_sock() *2)| | v
My question is how the smc_clcsock_release() could happen after the syn_recv_sock()?
IMO, the syn_recv_sock() should be called during the &smc->tcp_listen_work, which is corresponding to lsmc (listen smc). And in smc_clcsock_accept(), the lsmc->clcsock as the listening socket goes on to be used to accept a new connection. If the &smc->tcp_listen_work is not finished, *1) will wait for its finishing. It can only happen in following situation:
*4) sk_state is SMC_CLOSED, then no connection is accepted.
*5) old sk_state is SMC_LISTEN, TCP accept is successful. But current sk_state is SMC_CLOSED. Thus, no new smc connection.
What do you think? Please let me know if I have any lapse of thought.
Thanks,
Wenjia