Revert "soreuseport: Fix socket selection for SO_INCOMING_CPU."
This reverts commit 8741792d82 which is
commit b261eda84ec136240a9ca753389853a3a1bccca2 upstream.
It breaks the current Android ABI. If this is needed on any systems, it
can be brought back in the future in an ABI-safe way.
Bug: 161946584
Change-Id: I6521e18d523b4cc654d9cf451ab1ca7b79daac82
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
@@ -16,7 +16,6 @@ struct sock_reuseport {
|
||||
u16 max_socks; /* length of socks */
|
||||
u16 num_socks; /* elements in socks */
|
||||
u16 num_closed_socks; /* closed elements in socks */
|
||||
u16 incoming_cpu;
|
||||
/* The last synq overflow event timestamp of this
|
||||
* reuse->socks[] group.
|
||||
*/
|
||||
@@ -59,6 +58,5 @@ static inline bool reuseport_has_conns(struct sock *sk)
|
||||
}
|
||||
|
||||
void reuseport_has_conns_set(struct sock *sk);
|
||||
void reuseport_update_incoming_cpu(struct sock *sk, int val);
|
||||
|
||||
#endif /* _SOCK_REUSEPORT_H */
|
||||
|
||||
@@ -1304,7 +1304,7 @@ set_sndbuf:
|
||||
break;
|
||||
}
|
||||
case SO_INCOMING_CPU:
|
||||
reuseport_update_incoming_cpu(sk, val);
|
||||
WRITE_ONCE(sk->sk_incoming_cpu, val);
|
||||
break;
|
||||
|
||||
case SO_CNX_ADVICE:
|
||||
|
||||
@@ -37,70 +37,6 @@ void reuseport_has_conns_set(struct sock *sk)
|
||||
}
|
||||
EXPORT_SYMBOL(reuseport_has_conns_set);
|
||||
|
||||
static void __reuseport_get_incoming_cpu(struct sock_reuseport *reuse)
|
||||
{
|
||||
/* Paired with READ_ONCE() in reuseport_select_sock_by_hash(). */
|
||||
WRITE_ONCE(reuse->incoming_cpu, reuse->incoming_cpu + 1);
|
||||
}
|
||||
|
||||
static void __reuseport_put_incoming_cpu(struct sock_reuseport *reuse)
|
||||
{
|
||||
/* Paired with READ_ONCE() in reuseport_select_sock_by_hash(). */
|
||||
WRITE_ONCE(reuse->incoming_cpu, reuse->incoming_cpu - 1);
|
||||
}
|
||||
|
||||
static void reuseport_get_incoming_cpu(struct sock *sk, struct sock_reuseport *reuse)
|
||||
{
|
||||
if (sk->sk_incoming_cpu >= 0)
|
||||
__reuseport_get_incoming_cpu(reuse);
|
||||
}
|
||||
|
||||
static void reuseport_put_incoming_cpu(struct sock *sk, struct sock_reuseport *reuse)
|
||||
{
|
||||
if (sk->sk_incoming_cpu >= 0)
|
||||
__reuseport_put_incoming_cpu(reuse);
|
||||
}
|
||||
|
||||
void reuseport_update_incoming_cpu(struct sock *sk, int val)
|
||||
{
|
||||
struct sock_reuseport *reuse;
|
||||
int old_sk_incoming_cpu;
|
||||
|
||||
if (unlikely(!rcu_access_pointer(sk->sk_reuseport_cb))) {
|
||||
/* Paired with REAE_ONCE() in sk_incoming_cpu_update()
|
||||
* and compute_score().
|
||||
*/
|
||||
WRITE_ONCE(sk->sk_incoming_cpu, val);
|
||||
return;
|
||||
}
|
||||
|
||||
spin_lock_bh(&reuseport_lock);
|
||||
|
||||
/* This must be done under reuseport_lock to avoid a race with
|
||||
* reuseport_grow(), which accesses sk->sk_incoming_cpu without
|
||||
* lock_sock() when detaching a shutdown()ed sk.
|
||||
*
|
||||
* Paired with READ_ONCE() in reuseport_select_sock_by_hash().
|
||||
*/
|
||||
old_sk_incoming_cpu = sk->sk_incoming_cpu;
|
||||
WRITE_ONCE(sk->sk_incoming_cpu, val);
|
||||
|
||||
reuse = rcu_dereference_protected(sk->sk_reuseport_cb,
|
||||
lockdep_is_held(&reuseport_lock));
|
||||
|
||||
/* reuseport_grow() has detached a closed sk. */
|
||||
if (!reuse)
|
||||
goto out;
|
||||
|
||||
if (old_sk_incoming_cpu < 0 && val >= 0)
|
||||
__reuseport_get_incoming_cpu(reuse);
|
||||
else if (old_sk_incoming_cpu >= 0 && val < 0)
|
||||
__reuseport_put_incoming_cpu(reuse);
|
||||
|
||||
out:
|
||||
spin_unlock_bh(&reuseport_lock);
|
||||
}
|
||||
|
||||
static int reuseport_sock_index(struct sock *sk,
|
||||
const struct sock_reuseport *reuse,
|
||||
bool closed)
|
||||
@@ -128,7 +64,6 @@ static void __reuseport_add_sock(struct sock *sk,
|
||||
/* paired with smp_rmb() in reuseport_(select|migrate)_sock() */
|
||||
smp_wmb();
|
||||
reuse->num_socks++;
|
||||
reuseport_get_incoming_cpu(sk, reuse);
|
||||
}
|
||||
|
||||
static bool __reuseport_detach_sock(struct sock *sk,
|
||||
@@ -141,7 +76,6 @@ static bool __reuseport_detach_sock(struct sock *sk,
|
||||
|
||||
reuse->socks[i] = reuse->socks[reuse->num_socks - 1];
|
||||
reuse->num_socks--;
|
||||
reuseport_put_incoming_cpu(sk, reuse);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -152,7 +86,6 @@ static void __reuseport_add_closed_sock(struct sock *sk,
|
||||
reuse->socks[reuse->max_socks - reuse->num_closed_socks - 1] = sk;
|
||||
/* paired with READ_ONCE() in inet_csk_bind_conflict() */
|
||||
WRITE_ONCE(reuse->num_closed_socks, reuse->num_closed_socks + 1);
|
||||
reuseport_get_incoming_cpu(sk, reuse);
|
||||
}
|
||||
|
||||
static bool __reuseport_detach_closed_sock(struct sock *sk,
|
||||
@@ -166,7 +99,6 @@ static bool __reuseport_detach_closed_sock(struct sock *sk,
|
||||
reuse->socks[i] = reuse->socks[reuse->max_socks - reuse->num_closed_socks];
|
||||
/* paired with READ_ONCE() in inet_csk_bind_conflict() */
|
||||
WRITE_ONCE(reuse->num_closed_socks, reuse->num_closed_socks - 1);
|
||||
reuseport_put_incoming_cpu(sk, reuse);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -234,7 +166,6 @@ int reuseport_alloc(struct sock *sk, bool bind_inany)
|
||||
reuse->bind_inany = bind_inany;
|
||||
reuse->socks[0] = sk;
|
||||
reuse->num_socks = 1;
|
||||
reuseport_get_incoming_cpu(sk, reuse);
|
||||
rcu_assign_pointer(sk->sk_reuseport_cb, reuse);
|
||||
|
||||
out:
|
||||
@@ -278,7 +209,6 @@ static struct sock_reuseport *reuseport_grow(struct sock_reuseport *reuse)
|
||||
more_reuse->reuseport_id = reuse->reuseport_id;
|
||||
more_reuse->bind_inany = reuse->bind_inany;
|
||||
more_reuse->has_conns = reuse->has_conns;
|
||||
more_reuse->incoming_cpu = reuse->incoming_cpu;
|
||||
|
||||
memcpy(more_reuse->socks, reuse->socks,
|
||||
reuse->num_socks * sizeof(struct sock *));
|
||||
@@ -528,32 +458,18 @@ static struct sock *run_bpf_filter(struct sock_reuseport *reuse, u16 socks,
|
||||
static struct sock *reuseport_select_sock_by_hash(struct sock_reuseport *reuse,
|
||||
u32 hash, u16 num_socks)
|
||||
{
|
||||
struct sock *first_valid_sk = NULL;
|
||||
int i, j;
|
||||
|
||||
i = j = reciprocal_scale(hash, num_socks);
|
||||
do {
|
||||
struct sock *sk = reuse->socks[i];
|
||||
|
||||
if (sk->sk_state != TCP_ESTABLISHED) {
|
||||
/* Paired with WRITE_ONCE() in __reuseport_(get|put)_incoming_cpu(). */
|
||||
if (!READ_ONCE(reuse->incoming_cpu))
|
||||
return sk;
|
||||
|
||||
/* Paired with WRITE_ONCE() in reuseport_update_incoming_cpu(). */
|
||||
if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id())
|
||||
return sk;
|
||||
|
||||
if (!first_valid_sk)
|
||||
first_valid_sk = sk;
|
||||
}
|
||||
|
||||
while (reuse->socks[i]->sk_state == TCP_ESTABLISHED) {
|
||||
i++;
|
||||
if (i >= num_socks)
|
||||
i = 0;
|
||||
} while (i != j);
|
||||
if (i == j)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return first_valid_sk;
|
||||
return reuse->socks[i];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user