From: Willy Tarreau Date: Fri, 21 Apr 2023 08:46:45 +0000 (+0200) Subject: MINOR: quic_sock: index li->per_thr[] on local thread id, not global one X-Git-Tag: v2.8-dev8~42 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6a4d48b73633afc4b480b8989a5b2613033ed80d;p=thirdparty%2Fhaproxy.git MINOR: quic_sock: index li->per_thr[] on local thread id, not global one There's a li_per_thread array in each listener for use with QUIC listeners. Since thread groups were introduced, this array can be allocated too large because global.nbthread is allocated for each listener, while only no more than MIN(nbthread,MAX_THREADS_PER_GROUP) may be used by a single listener. This was because the global thread ID is used as the index instead of the local ID (since a listener may only be used by a single group). Let's just switch to local ID and reduce the allocated size. --- diff --git a/include/haproxy/listener-t.h b/include/haproxy/listener-t.h index 0f6adde3ad..f45c990a5a 100644 --- a/include/haproxy/listener-t.h +++ b/include/haproxy/listener-t.h @@ -246,7 +246,7 @@ struct listener { struct eb32_node id; /* place in the tree of used IDs */ } conf; /* config information */ - struct li_per_thread *per_thr; /* per-thread fields */ + struct li_per_thread *per_thr; /* per-thread fields (one per thread in the group) */ EXTRA_COUNTERS(extra_counters); }; diff --git a/src/listener.c b/src/listener.c index ad72c8eccf..d6e58ce69a 100644 --- a/src/listener.c +++ b/src/listener.c @@ -205,19 +205,21 @@ REGISTER_POST_DEINIT(accept_queue_deinit); #endif // USE_THREAD -/* Memory allocation and initialization of the per_thr field. +/* Memory allocation and initialization of the per_thr field (one entry per + * bound thread). * Returns 0 if the field has been successfully initialized, -1 on failure. */ int li_init_per_thr(struct listener *li) { + int nbthr = MIN(global.nbthread, MAX_THREADS_PER_GROUP); int i; /* allocate per-thread elements for listener */ - li->per_thr = calloc(global.nbthread, sizeof(*li->per_thr)); + li->per_thr = calloc(nbthr, sizeof(*li->per_thr)); if (!li->per_thr) return -1; - for (i = 0; i < global.nbthread; ++i) { + for (i = 0; i < nbthr; ++i) { MT_LIST_INIT(&li->per_thr[i].quic_accept.list); MT_LIST_INIT(&li->per_thr[i].quic_accept.conns); diff --git a/src/quic_sock.c b/src/quic_sock.c index d7d40982ed..196ad386d9 100644 --- a/src/quic_sock.c +++ b/src/quic_sock.c @@ -147,7 +147,7 @@ int quic_sock_accepting_conn(const struct receiver *rx) struct connection *quic_sock_accept_conn(struct listener *l, int *status) { struct quic_conn *qc; - struct li_per_thread *lthr = &l->per_thr[tid]; + struct li_per_thread *lthr = &l->per_thr[ti->ltid]; qc = MT_LIST_POP(<hr->quic_accept.conns, struct quic_conn *, accept_list); if (!qc || qc->flags & (QUIC_FL_CONN_CLOSING|QUIC_FL_CONN_DRAINING)) @@ -897,7 +897,7 @@ struct quic_accept_queue *quic_accept_queues; void quic_accept_push_qc(struct quic_conn *qc) { struct quic_accept_queue *queue = &quic_accept_queues[tid]; - struct li_per_thread *lthr = &qc->li->per_thr[tid]; + struct li_per_thread *lthr = &qc->li->per_thr[ti->ltid]; /* early return if accept is already in progress/done for this * connection