From: Yonghong Song <yhs@fb.com>
To: Martin KaFai Lau <kafai@fb.com>
Cc: <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eric Dumazet <edumazet@google.com>, <kernel-team@fb.com>,
Neal Cardwell <ncardwell@google.com>, <netdev@vger.kernel.org>,
Yuchung Cheng <ycheng@google.com>
Subject: Re: [PATCH bpf-next 6/8] bpf: tcp: bpf iter batching and lock_sock
Date: Tue, 29 Jun 2021 10:57:46 -0700 [thread overview]
Message-ID: <387750f4-4610-0c37-60c5-06e5a1c98e63@fb.com> (raw)
In-Reply-To: <20210629174458.2c5grwa37ehb55wo@kafai-mbp.dhcp.thefacebook.com>
On 6/29/21 10:44 AM, Martin KaFai Lau wrote:
> On Tue, Jun 29, 2021 at 10:27:17AM -0700, Yonghong Song wrote:
> [ ... ]
>
>>> +static int bpf_iter_tcp_realloc_batch(struct bpf_tcp_iter_state *iter,
>>> + unsigned int new_batch_sz)
>>> +{
>>> + struct sock **new_batch;
>>> +
>>> + new_batch = kvmalloc(sizeof(*new_batch) * new_batch_sz, GFP_USER);
>>
>> Since we return -ENOMEM below, should we have __GFP_NOWARN in kvmalloc
>> flags?
> will add in v2.
>
>>
>>> + if (!new_batch)
>>> + return -ENOMEM;
>>> +
>>> + bpf_iter_tcp_put_batch(iter);
>>> + kvfree(iter->batch);
>>> + iter->batch = new_batch;
>>> + iter->max_sk = new_batch_sz;
>>> +
>>> + return 0;
>>> +}
>>> +
>> [...]
>>> +
>>> static int bpf_iter_tcp_seq_show(struct seq_file *seq, void *v)
>>> {
>>> struct bpf_iter_meta meta;
>>> struct bpf_prog *prog;
>>> struct sock *sk = v;
>>> + bool slow;
>>> uid_t uid;
>>> + int ret;
>>> if (v == SEQ_START_TOKEN)
>>> return 0;
>>> + if (sk_fullsock(sk))
>>> + slow = lock_sock_fast(sk);
>>> +
>>> + if (unlikely(sk_unhashed(sk))) {
>>> + ret = SEQ_SKIP;
>>> + goto unlock;
>>> + }
>>
>> I am not a tcp expert. Maybe a dummy question.
>> Is it possible to do setsockopt() for listening socket?
>> What will happen if the listening sock is unhashed after the
>> above check?
> It won't happen because the sk has been locked before doing the
> unhashed check.
Ya, that is true. I guess I probably mean TCP_TIME_WAIT and
TCP_NEW_SYN_RECV sockets. We cannot do setsockopt() for
TCP_TIME_WAIT sockets since user space shouldn't be able
to access the socket any more.
But how about TCP_NEW_SYN_RECV sockets?
>
> Thanks for the review.
>
next prev parent reply other threads:[~2021-06-29 17:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-25 20:04 [PATCH bpf-next 0/8] bpf: Allow bpf tcp iter to do bpf_setsockopt Martin KaFai Lau
2021-06-25 20:04 ` [PATCH bpf-next 1/8] tcp: seq_file: Avoid skipping sk during tcp_seek_last_pos Martin KaFai Lau
2021-06-25 20:04 ` [PATCH bpf-next 2/8] tcp: seq_file: Refactor net and family matching Martin KaFai Lau
2021-06-25 20:05 ` [PATCH bpf-next 3/8] bpf: tcp: seq_file: Remove bpf_seq_afinfo from tcp_iter_state Martin KaFai Lau
2021-06-25 20:05 ` [PATCH bpf-next 4/8] tcp: seq_file: Add listening_get_first() Martin KaFai Lau
2021-06-25 20:05 ` [PATCH bpf-next 5/8] tcp: seq_file: Replace listening_hash with lhash2 Martin KaFai Lau
2021-06-25 20:05 ` [PATCH bpf-next 6/8] bpf: tcp: bpf iter batching and lock_sock Martin KaFai Lau
2021-06-29 17:27 ` Yonghong Song
2021-06-29 17:44 ` Martin KaFai Lau
2021-06-29 17:57 ` Yonghong Song [this message]
2021-06-29 18:06 ` Martin KaFai Lau
2021-06-29 18:55 ` Yonghong Song
2021-06-25 20:05 ` [PATCH bpf-next 7/8] bpf: tcp: Support bpf_setsockopt in bpf tcp iter Martin KaFai Lau
2021-06-25 20:05 ` [PATCH bpf-next 8/8] bpf: selftest: Test batching and " Martin KaFai Lau
2021-06-29 19:00 ` Yonghong Song
2021-06-29 19:04 ` [PATCH bpf-next 0/8] bpf: Allow bpf tcp iter to do bpf_setsockopt Yonghong Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=387750f4-4610-0c37-60c5-06e5a1c98e63@fb.com \
--to=yhs@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=edumazet@google.com \
--cc=kafai@fb.com \
--cc=kernel-team@fb.com \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=ycheng@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).