The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Breno Leitao <leitao@debian.org>
To: Stanislav Fomichev <sdf.kernel@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	 Kuniyuki Iwashima <kuniyu@google.com>,
	Willem de Bruijn <willemb@google.com>,
	 Neal Cardwell <ncardwell@google.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	 John Fastabend <john.fastabend@gmail.com>,
	Stanislav Fomichev <sdf@fomichev.me>,
	 Martin KaFai Lau <martin.lau@linux.dev>,
	Alexei Starovoitov <ast@kernel.org>,
	 Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	 Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Song Liu <song@kernel.org>,
	 Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>,
	 Emil Tsalapatis <emil@etsalapatis.com>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	 Shuah Khan <shuah@kernel.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	 bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	kernel-team@meta.com
Subject: Re: [PATCH net-next 1/3] net/tcp-ao: convert the getsockopt helpers to sockopt_t
Date: Sat, 21 Nov 2026 04:53:09 -0800	[thread overview]
Message-ID: <awGTN1cIEnnlAMPq@gmail.com> (raw)
In-Reply-To: <avdxDgmlDBTRgqM0@devvm16445.scu0.facebook.com>

On Fri, Nov 13, 2026 at 12:21:27PM -0800, Stanislav Fomichev wrote:
> On 11/12, Breno Leitao wrote:
> > @@ -2214,6 +2213,21 @@ static int tcp_ao_copy_mkts_to_user(const struct sock *sk,
> >  	}
> >  
> >  	bytes_to_write = min_t(int, user_len, sizeof(struct tcp_ao_getsockopt));
> > +
> 
> [..]
> 
> > +	/* The reply is up to nkeys entries, user_len apart, with the match
> > +	 * count in the first entry's nkeys, so it can outgrow optlen. Size it
> > +	 * by the keys on the socket rather than by the caller's nkeys.
> > +	 */
> > +	hlist_for_each_entry_rcu(key, &ao_info->head, node,
> > +				 lockdep_sock_is_held(sk))
> > +		nr_keys++;
> > +	reply_len = max(array_size(min(max_keys, nr_keys), user_len),
> > +			offsetofend(struct tcp_ao_getsockopt, nkeys));
> > +	err = sockopt_expand_out(sopt, reply_len);
> > +	if (err)
> > +		return err;
> > +	head = sopt->iter_out;
> 
> Is that faster / cleaner / more preferable than calling sockopt_expand_out
> on every iteration hlist_for_each_entry_rcu below?

sockopt_expand_out() can't be called once something went through
iter_out. It re-anchors the iterator at the head of optval, so it WARNs
and returns -EINVAL if the iterator has already moved.

That check came in v2 of the series that added the helper [1], because
a late call would rewind the write cursor. With a call per key, the
second key would trip it.

So the size has to be known before the first entry is written, which is
why the keys are counted first. ip_mc_gsfget() does the same and sizes
its source list by min(sl_count, gf_numsrc). tcp_ao_info just keeps no
key count, hence the walk.

Sizing by nkeys alone doesn't work either: a large nkeys would hit the
MAX_RW_COUNT check and get -EINVAL, where today it copies only the keys
that match.

The extra walk seems very cheap. The keys come from sock_kmalloc(), so
optmem_max caps how many a socket holds, and the socket lock keeps the
list stable between the two walks.

I'll say this in the comment and resping a v2.

Thanks for the review, you are being key to this whole convertion,
--breno

[1] https://lore.kernel.org/20260914-getsockopt_phase6-v2-0-e48befc9602e@debian.org

  reply	other threads:[~2026-11-21 12:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 17:05 [PATCH net-next 0/3] tcp: convert the SOL_TCP getsockopt path to sockopt_t Breno Leitao
2026-11-12 17:05 ` [PATCH net-next 1/3] net/tcp-ao: convert the getsockopt helpers " Breno Leitao
2026-11-13 20:21   ` Stanislav Fomichev
2026-11-21 12:53     ` Breno Leitao [this message]
2026-11-12 17:05 ` [PATCH net-next 2/3] tcp: convert do_tcp_getsockopt() " Breno Leitao
2026-11-13 20:21   ` Stanislav Fomichev
2026-11-15 17:00   ` netdev-bot+sashiko
2026-11-12 17:05 ` [PATCH net-next 3/3] selftests: net: getsockopt_iter: cover tcp Breno Leitao
2026-11-13 20:22   ` Stanislav Fomichev
2026-11-15 17:01   ` netdev-bot+sashiko

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=awGTN1cIEnnlAMPq@gmail.com \
    --to=leitao@debian.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=emil@etsalapatis.com \
    --cc=horms@kernel.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf.kernel@gmail.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=willemb@google.com \
    --cc=yonghong.song@linux.dev \
    /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