From: Xin Long <lucien.xin@gmail.com>
To: Paolo Abeni <pabeni@redhat.com>
Cc: network dev <netdev@vger.kernel.org>,
davem@davemloft.net, kuba@kernel.org,
Eric Dumazet <edumazet@google.com>,
Simon Horman <horms@kernel.org>,
Stefan Metzmacher <metze@samba.org>,
Moritz Buhl <mbuhl@openbsd.org>,
Tyler Fanelli <tfanelli@redhat.com>,
Pengtao He <hepengtao@xiaomi.com>,
linux-cifs@vger.kernel.org, Steve French <smfrench@gmail.com>,
Namjae Jeon <linkinjeon@kernel.org>,
Paulo Alcantara <pc@manguebit.com>, Tom Talpey <tom@talpey.com>,
kernel-tls-handshake@lists.linux.dev,
Chuck Lever <chuck.lever@oracle.com>,
Jeff Layton <jlayton@kernel.org>,
Benjamin Coddington <bcodding@redhat.com>,
Steve Dickson <steved@redhat.com>, Hannes Reinecke <hare@suse.de>,
Alexander Aring <aahringo@redhat.com>,
David Howells <dhowells@redhat.com>,
Cong Wang <xiyou.wangcong@gmail.com>,
"D . Wythe" <alibuda@linux.alibaba.com>,
Jason Baron <jbaron@akamai.com>,
illiliti <illiliti@protonmail.com>,
Sabrina Dubroca <sd@queasysnail.net>,
Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
Daniel Stenberg <daniel@haxx.se>,
Andy Gospodarek <andrew.gospodarek@broadcom.com>
Subject: Re: [PATCH net-next v2 06/15] quic: add stream management
Date: Sat, 23 Aug 2025 13:14:52 -0400 [thread overview]
Message-ID: <CADvbK_dJoCa5t3OA61gJtMkq1uG7C77MEMwz9XXm_HLc4FgHWA@mail.gmail.com> (raw)
In-Reply-To: <a79bfa8b-657f-4358-99f3-2774eb65d49f@redhat.com>
On Thu, Aug 21, 2025 at 9:43 AM Paolo Abeni <pabeni@redhat.com> wrote:
>
> On 8/18/25 4:04 PM, Xin Long wrote:
> > +/* Check if a stream ID is valid for sending. */
> > +static bool quic_stream_id_send(s64 stream_id, bool is_serv)
> > +{
> > + u8 type = (stream_id & QUIC_STREAM_TYPE_MASK);
> > +
> > + if (is_serv) {
> > + if (type == QUIC_STREAM_TYPE_CLIENT_UNI)
> > + return false;
> > + } else if (type == QUIC_STREAM_TYPE_SERVER_UNI) {
> > + return false;
> > + }
> > + return true;
> > +}
> > +
> > +/* Check if a stream ID is valid for receiving. */
> > +static bool quic_stream_id_recv(s64 stream_id, bool is_serv)
> > +{
> > + u8 type = (stream_id & QUIC_STREAM_TYPE_MASK);
> > +
> > + if (is_serv) {
> > + if (type == QUIC_STREAM_TYPE_SERVER_UNI)
> > + return false;
> > + } else if (type == QUIC_STREAM_TYPE_CLIENT_UNI) {
> > + return false;
> > + }
> > + return true;
> > +}
>
> The above two functions could be implemented using a common helper
> saving some code duplication.
Not yet sure if it's worth a helper, I need to think about it.
>
> > +/* Create and register new streams for sending. */
> > +static struct quic_stream *quic_stream_send_create(struct quic_stream_table *streams,
> > + s64 max_stream_id, u8 is_serv)
> > +{
> > + struct quic_stream *stream;
> > + s64 stream_id;
> > +
> > + stream_id = streams->send.next_bidi_stream_id;
> > + if (quic_stream_id_uni(max_stream_id))
> > + stream_id = streams->send.next_uni_stream_id;
> > +
> > + /* rfc9000#section-2.1: A stream ID that is used out of order results in all streams
> > + * of that type with lower-numbered stream IDs also being opened.
> > + */
> > + while (stream_id <= max_stream_id) {
>
> Is wrap around thererically possible?
> Who provided `max_stream_id`, the user-space? or a remote pear? what if
> max_stream_id - stream_id is say 1M ?
There are two values limiting this:
1. streams->send.max_uni/bidi_stream_id:
the max_uni/bidi_stream_id that peer informs to be open.
2. streams->send.max_streams_uni/bidi (max value: QUIC_MAX_STREAMS(4096)):
to limit the number of the existing streams.
>
> [...]
> > +/* Check if a receive stream ID is already closed. */
> > +static bool quic_stream_id_recv_closed(struct quic_stream_table *streams, s64 stream_id)
> > +{
> > + if (quic_stream_id_uni(stream_id)) {
> > + if (stream_id < streams->recv.next_uni_stream_id)
> > + return true;
> > + } else {
> > + if (stream_id < streams->recv.next_bidi_stream_id)
> > + return true;
> > + }
> > + return false;
> > +}
>
> I guess the above answer my previous questions, but I think that memory
> accounting for stream allocation is still deserverd.
>
I can give it a try. sk_r/wmem_schedule() should be used for this I suppose.
> > +
> > +/* Check if a receive stream ID exceeds would exceed local's limits. */
> > +static bool quic_stream_id_recv_exceeds(struct quic_stream_table *streams, s64 stream_id)
> > +{
> > + if (quic_stream_id_uni(stream_id)) {
> > + if (stream_id > streams->recv.max_uni_stream_id)
> > + return true;
> > + } else {
> > + if (stream_id > streams->recv.max_bidi_stream_id)
> > + return true;
> > + }
> > + return false;
> > +}
> > +
> > +/* Check if a send stream ID would exceed peer's limits. */
> > +bool quic_stream_id_send_exceeds(struct quic_stream_table *streams, s64 stream_id)
> > +{
> > + u64 nstreams;
> > +
> > + if (quic_stream_id_uni(stream_id)) {
> > + if (stream_id > streams->send.max_uni_stream_id)
> > + return true;
> > + } else {
> > + if (stream_id > streams->send.max_bidi_stream_id)
> > + return true;
> > + }
> > +
> > + if (quic_stream_id_uni(stream_id)) {
> > + stream_id -= streams->send.next_uni_stream_id;
> > + nstreams = quic_stream_id_to_streams(stream_id);
> > + if (nstreams + streams->send.streams_uni > streams->send.max_streams_uni)
> > + return true;
> > + } else {
> > + stream_id -= streams->send.next_bidi_stream_id;
> > + nstreams = quic_stream_id_to_streams(stream_id);
> > + if (nstreams + streams->send.streams_bidi > streams->send.max_streams_bidi)
> > + return true;
> > + }
> > + return false;
> > +}
> > +
> > +/* Get or create a send stream by ID. */
> > +struct quic_stream *quic_stream_send_get(struct quic_stream_table *streams, s64 stream_id,
> > + u32 flags, bool is_serv)
> > +{
> > + struct quic_stream *stream;
> > +
> > + if (!quic_stream_id_send(stream_id, is_serv))
> > + return ERR_PTR(-EINVAL);
> > +
> > + stream = quic_stream_find(streams, stream_id);
> > + if (stream) {
> > + if ((flags & MSG_STREAM_NEW) &&
> > + stream->send.state != QUIC_STREAM_SEND_STATE_READY)
> > + return ERR_PTR(-EINVAL);
> > + return stream;
> > + }
> > +
> > + if (quic_stream_id_send_closed(streams, stream_id))
> > + return ERR_PTR(-ENOSTR);
> > +
> > + if (!(flags & MSG_STREAM_NEW))
> > + return ERR_PTR(-EINVAL);
> > +
> > + if (quic_stream_id_send_exceeds(streams, stream_id))
> > + return ERR_PTR(-EAGAIN);
> > +
> > + stream = quic_stream_send_create(streams, stream_id, is_serv);
> > + if (!stream)
> > + return ERR_PTR(-ENOSTR);
> > + streams->send.active_stream_id = stream_id;
> > + return stream;
>
> There is no locking at all in lookup/add/remove. Lacking the caller of
> such functions is hard to say if that is safe. You should add some info
> about that in the commit message (or lock here ;)
>
stream_hashtable is per connection/socket, it's always protected by
sock lock, I will add information into the commit message.
Thanks.
next prev parent reply other threads:[~2025-08-23 17:15 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-18 14:04 [PATCH net-next v2 00/15] net: introduce QUIC infrastructure and core subcomponents Xin Long
2025-08-18 14:04 ` [PATCH net-next v2 01/15] net: define IPPROTO_QUIC and SOL_QUIC constants Xin Long
2025-08-18 14:31 ` Stefan Metzmacher
2025-08-18 16:20 ` Matthieu Baerts
2025-08-18 18:37 ` Xin Long
2025-08-19 8:10 ` Namjae Jeon
2025-08-21 8:24 ` Stefan Metzmacher
2025-08-18 14:04 ` [PATCH net-next v2 02/15] net: build socket infrastructure for QUIC protocol Xin Long
2025-08-21 11:17 ` Paolo Abeni
2025-08-23 18:38 ` Xin Long
2025-08-18 14:04 ` [PATCH net-next v2 03/15] quic: provide common utilities and data structures Xin Long
2025-08-21 12:58 ` Paolo Abeni
2025-08-23 18:15 ` Xin Long
2025-08-18 14:04 ` [PATCH net-next v2 04/15] quic: provide family ops for address and protocol Xin Long
2025-08-21 13:17 ` Paolo Abeni
2025-08-23 17:22 ` Xin Long
2025-08-18 14:04 ` [PATCH net-next v2 05/15] quic: provide quic.h header files for kernel and userspace Xin Long
2025-08-18 14:04 ` [PATCH net-next v2 06/15] quic: add stream management Xin Long
2025-08-21 13:43 ` Paolo Abeni
2025-08-23 17:14 ` Xin Long [this message]
2025-08-18 14:04 ` [PATCH net-next v2 07/15] quic: add connection id management Xin Long
2025-08-21 13:55 ` Paolo Abeni
2025-08-23 15:57 ` Xin Long
2025-08-22 17:10 ` Jason Baron
2025-08-23 16:15 ` Xin Long
2025-08-18 14:04 ` [PATCH net-next v2 08/15] quic: add path management Xin Long
2025-08-21 14:18 ` Paolo Abeni
2025-08-23 15:40 ` Xin Long
2025-08-18 14:04 ` [PATCH net-next v2 09/15] quic: add congestion control Xin Long
2025-08-18 14:04 ` [PATCH net-next v2 10/15] quic: add packet number space Xin Long
2025-08-18 14:04 ` [PATCH net-next v2 11/15] quic: add crypto key derivation and installation Xin Long
2025-08-18 14:04 ` [PATCH net-next v2 12/15] quic: add crypto packet encryption and decryption Xin Long
2025-08-18 14:04 ` [PATCH net-next v2 13/15] quic: add timer management Xin Long
2025-08-18 14:04 ` [PATCH net-next v2 14/15] quic: add frame encoder and decoder base Xin Long
2025-08-18 14:04 ` [PATCH net-next v2 15/15] quic: add packet builder and parser base Xin Long
2025-08-23 15:20 ` [PATCH net-next v2 00/15] net: introduce QUIC infrastructure and core subcomponents John Ericson
2025-08-24 17:57 ` Xin Long
2025-08-26 21:48 ` Xin Long
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=CADvbK_dJoCa5t3OA61gJtMkq1uG7C77MEMwz9XXm_HLc4FgHWA@mail.gmail.com \
--to=lucien.xin@gmail.com \
--cc=aahringo@redhat.com \
--cc=alibuda@linux.alibaba.com \
--cc=andrew.gospodarek@broadcom.com \
--cc=bcodding@redhat.com \
--cc=chuck.lever@oracle.com \
--cc=daniel@haxx.se \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=edumazet@google.com \
--cc=hare@suse.de \
--cc=hepengtao@xiaomi.com \
--cc=horms@kernel.org \
--cc=illiliti@protonmail.com \
--cc=jbaron@akamai.com \
--cc=jlayton@kernel.org \
--cc=kernel-tls-handshake@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=marcelo.leitner@gmail.com \
--cc=mbuhl@openbsd.org \
--cc=metze@samba.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pc@manguebit.com \
--cc=sd@queasysnail.net \
--cc=smfrench@gmail.com \
--cc=steved@redhat.com \
--cc=tfanelli@redhat.com \
--cc=tom@talpey.com \
--cc=xiyou.wangcong@gmail.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).