Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp191688ybb; Thu, 19 Mar 2020 19:39:10 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtMgLvU0s0kTcwJN80LBsqClisoHfjDXF0hU9xEMBo/9L/Z1Yl0C6Q5AADEOLCocTlz4VHH X-Received: by 2002:a9d:f05:: with SMTP id 5mr4797125ott.263.1584671950045; Thu, 19 Mar 2020 19:39:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584671950; cv=none; d=google.com; s=arc-20160816; b=W89E7qlBjIJ38/KleGzQ1th2lphsFvGkVFb/0FUA0Ti9uZ3csOVx3TH1lhCek6N1gO aBKUXOLTaKI6OvB5y5w4ZJ1eoagXFj6TrlmeSlWusAqWg8e0sTftFXF5i/3tE1h4VeRg TQfc+PH3MqA+2TDdhqA4h7kNHffAlFaw8G+Ze0FmVkJXFabd3xb/Ol49r96L60gLUr1L uDymmfLZbnEwso76PVrAlMolr5shXyYSSNDfLZQa9ZLd0/BbyG9bCk+mQ2K9oYDulIxH b5ZqOvS2Z/6qvLCD9joAl9JrqfgRO46u6simwiAK3ZAknj0HPZJKbB3a9DfS2ApF4tBO cYdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=b+xLRXzHP/uD1PUZAzoJiqb8D0d6d36preygPPnVqcI=; b=WcdXFeIDXmTtEa05TZxGDLUAtvPW8ofPpy+Nw4LMYkNtUTKrMQHiizrfJGWMuzqQiF R0K2A6iY/zXrMBhGZpP4L4xLqxh05vA+V8eiWnwt2TI6TfVsiu8Dsis/wrb70cxHNtev G46jrYFsRdx3qQxypSGBrFKdUpfsI72o2DiklPbWoQ0iffZ+0LpYFBOG1vA4VJHDTZjM /SiEtHSJ+3Kn6bnNbksQPwDp3hFkfPdTS6gIf5IdlLIYJYxyK4uWGvEi428H2wCf+loM PLTdvwrk9hp2yC7pqZGVM3QAlB+VM2ppOoPUH/uaIBvJhg4yS5uAMtpwvwN6egpQeXR8 +2SA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g22si2285566otn.56.2020.03.19.19.38.58; Thu, 19 Mar 2020 19:39:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726970AbgCTCim (ORCPT + 99 others); Thu, 19 Mar 2020 22:38:42 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:39086 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725856AbgCTCik (ORCPT ); Thu, 19 Mar 2020 22:38:40 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 41D6693372D32ECF8ABA; Fri, 20 Mar 2020 10:38:37 +0800 (CST) Received: from localhost (10.173.223.234) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Fri, 20 Mar 2020 10:38:29 +0800 From: YueHaibing To: , , , CC: , , , , , YueHaibing Subject: [PATCH bpf-next 2/2] bpf: tcp: Make tcp_bpf_recvmsg static Date: Fri, 20 Mar 2020 10:34:26 +0800 Message-ID: <20200320023426.60684-3-yuehaibing@huawei.com> X-Mailer: git-send-email 2.10.2.windows.1 In-Reply-To: <20200320023426.60684-1-yuehaibing@huawei.com> References: <20200319124631.58432-1-yuehaibing@huawei.com> <20200320023426.60684-1-yuehaibing@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.173.223.234] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After commit f747632b608f ("bpf: sockmap: Move generic sockmap hooks from BPF TCP"), tcp_bpf_recvmsg() is not used out of tcp_bpf.c, so make it static and remove it from tcp.h. Also move it to BPF_STREAM_PARSER #ifdef to fix unused function warnings. Signed-off-by: YueHaibing --- include/net/tcp.h | 2 - net/ipv4/tcp_bpf.c | 124 ++++++++++++++++++++++----------------------- 2 files changed, 62 insertions(+), 64 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 43fa07a36fa6..5fa9eacd965a 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -2207,8 +2207,6 @@ static inline void tcp_bpf_clone(const struct sock *sk, struct sock *newsk) #ifdef CONFIG_NET_SOCK_MSG int tcp_bpf_sendmsg_redir(struct sock *sk, struct sk_msg *msg, u32 bytes, int flags); -int tcp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, - int nonblock, int flags, int *addr_len); int __tcp_bpf_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg, int len, int flags); #endif /* CONFIG_NET_SOCK_MSG */ diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c index 37c91f25cae3..5a05327f97c1 100644 --- a/net/ipv4/tcp_bpf.c +++ b/net/ipv4/tcp_bpf.c @@ -10,25 +10,6 @@ #include #include -static int tcp_bpf_wait_data(struct sock *sk, struct sk_psock *psock, - int flags, long timeo, int *err) -{ - DEFINE_WAIT_FUNC(wait, woken_wake_function); - int ret = 0; - - if (!timeo) - return ret; - - add_wait_queue(sk_sleep(sk), &wait); - sk_set_bit(SOCKWQ_ASYNC_WAITDATA, sk); - ret = sk_wait_event(sk, &timeo, - !list_empty(&psock->ingress_msg) || - !skb_queue_empty(&sk->sk_receive_queue), &wait); - sk_clear_bit(SOCKWQ_ASYNC_WAITDATA, sk); - remove_wait_queue(sk_sleep(sk), &wait); - return ret; -} - int __tcp_bpf_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg, int len, int flags) { @@ -102,49 +83,6 @@ int __tcp_bpf_recvmsg(struct sock *sk, struct sk_psock *psock, } EXPORT_SYMBOL_GPL(__tcp_bpf_recvmsg); -int tcp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, - int nonblock, int flags, int *addr_len) -{ - struct sk_psock *psock; - int copied, ret; - - psock = sk_psock_get(sk); - if (unlikely(!psock)) - return tcp_recvmsg(sk, msg, len, nonblock, flags, addr_len); - if (unlikely(flags & MSG_ERRQUEUE)) - return inet_recv_error(sk, msg, len, addr_len); - if (!skb_queue_empty(&sk->sk_receive_queue) && - sk_psock_queue_empty(psock)) - return tcp_recvmsg(sk, msg, len, nonblock, flags, addr_len); - lock_sock(sk); -msg_bytes_ready: - copied = __tcp_bpf_recvmsg(sk, psock, msg, len, flags); - if (!copied) { - int data, err = 0; - long timeo; - - timeo = sock_rcvtimeo(sk, nonblock); - data = tcp_bpf_wait_data(sk, psock, flags, timeo, &err); - if (data) { - if (!sk_psock_queue_empty(psock)) - goto msg_bytes_ready; - release_sock(sk); - sk_psock_put(sk, psock); - return tcp_recvmsg(sk, msg, len, nonblock, flags, addr_len); - } - if (err) { - ret = err; - goto out; - } - copied = -EAGAIN; - } - ret = copied; -out: - release_sock(sk); - sk_psock_put(sk, psock); - return ret; -} - static int bpf_tcp_ingress(struct sock *sk, struct sk_psock *psock, struct sk_msg *msg, u32 apply_bytes, int flags) { @@ -299,6 +237,68 @@ static bool tcp_bpf_stream_read(const struct sock *sk) return !empty; } +static int tcp_bpf_wait_data(struct sock *sk, struct sk_psock *psock, + int flags, long timeo, int *err) +{ + DEFINE_WAIT_FUNC(wait, woken_wake_function); + int ret = 0; + + if (!timeo) + return ret; + + add_wait_queue(sk_sleep(sk), &wait); + sk_set_bit(SOCKWQ_ASYNC_WAITDATA, sk); + ret = sk_wait_event(sk, &timeo, + !list_empty(&psock->ingress_msg) || + !skb_queue_empty(&sk->sk_receive_queue), &wait); + sk_clear_bit(SOCKWQ_ASYNC_WAITDATA, sk); + remove_wait_queue(sk_sleep(sk), &wait); + return ret; +} + +static int tcp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, + int nonblock, int flags, int *addr_len) +{ + struct sk_psock *psock; + int copied, ret; + + psock = sk_psock_get(sk); + if (unlikely(!psock)) + return tcp_recvmsg(sk, msg, len, nonblock, flags, addr_len); + if (unlikely(flags & MSG_ERRQUEUE)) + return inet_recv_error(sk, msg, len, addr_len); + if (!skb_queue_empty(&sk->sk_receive_queue) && + sk_psock_queue_empty(psock)) + return tcp_recvmsg(sk, msg, len, nonblock, flags, addr_len); + lock_sock(sk); +msg_bytes_ready: + copied = __tcp_bpf_recvmsg(sk, psock, msg, len, flags); + if (!copied) { + int data, err = 0; + long timeo; + + timeo = sock_rcvtimeo(sk, nonblock); + data = tcp_bpf_wait_data(sk, psock, flags, timeo, &err); + if (data) { + if (!sk_psock_queue_empty(psock)) + goto msg_bytes_ready; + release_sock(sk); + sk_psock_put(sk, psock); + return tcp_recvmsg(sk, msg, len, nonblock, flags, addr_len); + } + if (err) { + ret = err; + goto out; + } + copied = -EAGAIN; + } + ret = copied; +out: + release_sock(sk); + sk_psock_put(sk, psock); + return ret; +} + static int tcp_bpf_send_verdict(struct sock *sk, struct sk_psock *psock, struct sk_msg *msg, int *copied, int flags) { -- 2.17.1