Thread (16 messages) flat view 16 messages, 2 authors, 2021-06-29

Re: [PATCH bpf-next 6/8] bpf: tcp: bpf iter batching and lock_sock

From: Martin KaFai Lau <hidden>
Date: 2021-06-29 17:45:21
Also in: bpf

On Tue, Jun 29, 2021 at 10:27:17AM -0700, Yonghong Song wrote:
[ ... ]
quoted
+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.
quoted
+	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;
+}
+
[...]
quoted
+
  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.

Thanks for the review.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help