From patchwork Wed Dec 20 03:12:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 851188 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HRjUpGqy"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3z1fyP2d8Tz9sNV for ; Wed, 20 Dec 2017 14:14:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754221AbdLTDO0 (ORCPT ); Tue, 19 Dec 2017 22:14:26 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:41583 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754117AbdLTDN0 (ORCPT ); Tue, 19 Dec 2017 22:13:26 -0500 Received: by mail-pg0-f68.google.com with SMTP id o2so11408588pgc.8; Tue, 19 Dec 2017 19:13:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=q0ApGGYtpXrepsKh3FM90lGedtYWuMu0qz8ACIkT9Yg=; b=HRjUpGqyScYc6OdoxUfYDYBXxHy4YIiaWCP3I6RUZvI/RA19W05LpEzaQVXdc8FZx8 IzjcgzL9LpRyi/FwKDyNQLQfLLRSykQRdr1vUqDpH4ZJ3vhMIYuLvDHX1TLmiQyugA9n jprbjUvD8HZN5+GoaopnY9w/z1M/+R4ez3op1NAS9++HO+5SH+5yE/+MkVEOwKlr25rO hwW+S9U0+vcROQhX2qLj38yTQUe+qNo4lG71EP1q11CB8jF/Z7W/1EAvEBNZyOSzqdGq 5eZL+vD2uuG3zRFEHZ9jL6Y2rdRaVcoskYCCPF+kpggq2/DtcwfDUpD66rl2cYN2TybH Hm5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=q0ApGGYtpXrepsKh3FM90lGedtYWuMu0qz8ACIkT9Yg=; b=d0k16k6dM197i5aLMn6d8CagfLBHrLWINXmdF0XUA+VTgVz8a/9ptul+PISvpaIVNS xW4jSg+IU03UPKxzsa0Y1AiVTC3bolcHVuZvgfBFO3AdZDmO2czlAM8glUB2CElZvGPI ypSmT9O1xWGF4WYJY7zaSLuYdINRyEM8ddqI2Y1miBElJejTQTHUREzL3W99W2/pRIrk Ew7i+UkN4h1ErV7gwAjKFPnXWGucrzxz5XdW7BjbwK0CsrUMnfSjg3BAAnvc8Vh50D5G gLMAZL6xdYuGajMAWyu2i5FZhIyxZFoQ9qJ6oOnPSewn1Fc8gkCsWzT9XGC1VGr9aPCJ 8W2g== X-Gm-Message-State: AKGB3mK6dAcwWBpUz4AvQvN7VWv/7mxB3kshjz2hFZUtwkSUzv64zFiJ x4Tbe6NTlPk23VARNz/PYgc= X-Google-Smtp-Source: ACJfBovGRtckE6wasBWc20hvU5KM9mMQoBpHigaFZSVd7oc3Vd3KrpRaiuhurGpZmyNSf8+7exu4cA== X-Received: by 10.101.81.73 with SMTP id g9mr4957503pgq.137.1513739605498; Tue, 19 Dec 2017 19:13:25 -0800 (PST) Received: from li1588-6.members.linode.com (li1588-6.members.linode.com. [139.162.104.6]) by smtp.gmail.com with ESMTPSA id x4sm31401314pfb.13.2017.12.19.19.13.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Dec 2017 19:13:24 -0800 (PST) From: Yafang Shao To: songliubraving@fb.com, davem@davemloft.net, marcelo.leitner@gmail.com, rostedt@goodmis.org Cc: bgregg@netflix.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yafang Shao Subject: [PATCH v3 net-next 3/5] net: sock: replace sk_state_load with inet_sk_state_load and remove sk_state_store Date: Wed, 20 Dec 2017 11:12:52 +0800 Message-Id: <1513739574-3345-4-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1513739574-3345-1-git-send-email-laoar.shao@gmail.com> References: <1513739574-3345-1-git-send-email-laoar.shao@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org sk_state_load is only used by AF_INET/AF_INET6, so rename it to inet_sk_state_load and move it into inet_sock.h. sk_state_store is removed as it is not used any more. Signed-off-by: Yafang Shao --- include/net/inet_sock.h | 25 ++++++++++++++++++++++++- include/net/sock.h | 25 ------------------------- net/ipv4/inet_connection_sock.c | 2 +- net/ipv4/tcp.c | 4 ++-- net/ipv4/tcp_diag.c | 2 +- net/ipv4/tcp_ipv4.c | 2 +- net/ipv6/tcp_ipv6.c | 2 +- 7 files changed, 30 insertions(+), 32 deletions(-) diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h index a3431a4..0a671c3 100644 --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h @@ -290,9 +290,32 @@ static inline void inet_sk_copy_descendant(struct sock *sk_to, #endif int inet_sk_rebuild_header(struct sock *sk); -void inet_sk_set_state(struct sock *sk, int state); + +/** + * inet_sk_state_load - read sk->sk_state for lockless contexts + * @sk: socket pointer + * + * Paired with inet_sk_state_store(). Used in places we don't hold socket lock: + * tcp_diag_get_info(), tcp_get_info(), tcp_poll(), get_tcp4_sock() ... + */ +static inline int inet_sk_state_load(const struct sock *sk) +{ + /* state change might impact lockless readers. */ + return smp_load_acquire(&sk->sk_state); +} + +/** + * inet_sk_state_store - update sk->sk_state + * @sk: socket pointer + * @newstate: new state + * + * Paired with inet_sk_state_load(). Should be used in contexts where + * state change might impact lockless readers. + */ void inet_sk_state_store(struct sock *sk, int newstate); +void inet_sk_set_state(struct sock *sk, int state); + static inline unsigned int __inet_ehashfn(const __be32 laddr, const __u16 lport, const __be32 faddr, diff --git a/include/net/sock.h b/include/net/sock.h index 9a90472..4fd211b 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -2332,31 +2332,6 @@ static inline bool sk_listener(const struct sock *sk) return (1 << sk->sk_state) & (TCPF_LISTEN | TCPF_NEW_SYN_RECV); } -/** - * sk_state_load - read sk->sk_state for lockless contexts - * @sk: socket pointer - * - * Paired with sk_state_store(). Used in places we do not hold socket lock : - * tcp_diag_get_info(), tcp_get_info(), tcp_poll(), get_tcp4_sock() ... - */ -static inline int sk_state_load(const struct sock *sk) -{ - return smp_load_acquire(&sk->sk_state); -} - -/** - * sk_state_store - update sk->sk_state - * @sk: socket pointer - * @newstate: new state - * - * Paired with sk_state_load(). Should be used in contexts where - * state change might impact lockless readers. - */ -static inline void sk_state_store(struct sock *sk, int newstate) -{ - smp_store_release(&sk->sk_state, newstate); -} - void sock_enable_timestamp(struct sock *sk, int flag); int sock_get_timestamp(struct sock *, struct timeval __user *); int sock_get_timestampns(struct sock *, struct timespec __user *); diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index f460fc0..12410ec 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -685,7 +685,7 @@ static void reqsk_timer_handler(struct timer_list *t) int max_retries, thresh; u8 defer_accept; - if (sk_state_load(sk_listener) != TCP_LISTEN) + if (inet_sk_state_load(sk_listener) != TCP_LISTEN) goto drop; max_retries = icsk->icsk_syn_retries ? : net->ipv4.sysctl_tcp_synack_retries; diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index d408fb4..67d39b7 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -502,7 +502,7 @@ unsigned int tcp_poll(struct file *file, struct socket *sock, poll_table *wait) sock_poll_wait(file, sk_sleep(sk), wait); - state = sk_state_load(sk); + state = inet_sk_state_load(sk); if (state == TCP_LISTEN) return inet_csk_listen_poll(sk); @@ -2916,7 +2916,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info) if (sk->sk_type != SOCK_STREAM) return; - info->tcpi_state = sk_state_load(sk); + info->tcpi_state = inet_sk_state_load(sk); /* Report meaningful fields for all TCP states, including listeners */ rate = READ_ONCE(sk->sk_pacing_rate); diff --git a/net/ipv4/tcp_diag.c b/net/ipv4/tcp_diag.c index abbf0ed..81148f7 100644 --- a/net/ipv4/tcp_diag.c +++ b/net/ipv4/tcp_diag.c @@ -24,7 +24,7 @@ static void tcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r, { struct tcp_info *info = _info; - if (sk_state_load(sk) == TCP_LISTEN) { + if (inet_sk_state_load(sk) == TCP_LISTEN) { r->idiag_rqueue = sk->sk_ack_backlog; r->idiag_wqueue = sk->sk_max_ack_backlog; } else if (sk->sk_type == SOCK_STREAM) { diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 77ea45d..67ef303 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -2281,7 +2281,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i) timer_expires = jiffies; } - state = sk_state_load(sk); + state = inet_sk_state_load(sk); if (state == TCP_LISTEN) rx_queue = sk->sk_ack_backlog; else diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 1f04ec0..af2b2a2 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1795,7 +1795,7 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i) timer_expires = jiffies; } - state = sk_state_load(sp); + state = inet_sk_state_load(sp); if (state == TCP_LISTEN) rx_queue = sp->sk_ack_backlog; else