Skip to content

Commit

Permalink
QUIC APL: Avoid having a mutex variable where not needed
Browse files Browse the repository at this point in the history
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from #23334)
  • Loading branch information
hlandau committed Mar 10, 2024
1 parent 02d4571 commit 06ba67d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ssl/quic/quic_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,11 @@ static void qc_cleanup(QUIC_CONNECTION *qc, int have_lock)
qc->engine = NULL;
}

#if defined(OPENSSL_THREADS)
if (have_lock)
/* tsan doesn't like freeing locked mutexes */
ossl_crypto_mutex_unlock(qc->mutex);

#if defined(OPENSSL_THREADS)
if (qc->listener == NULL)
ossl_crypto_mutex_free(&qc->mutex);
#endif
Expand All @@ -569,7 +569,9 @@ static void quic_free_listener(QCTX *ctx)
ossl_quic_port_drop_incoming(ctx->ql->port);
ossl_quic_port_free(ctx->ql->port);
ossl_quic_engine_free(ctx->ql->engine);
#if defined(OPENSSL_THREADS)
ossl_crypto_mutex_free(&ctx->ql->mutex);
#endif
}

QUIC_TAKES_LOCK
Expand Down Expand Up @@ -1642,7 +1644,9 @@ static int create_channel(QUIC_CONNECTION *qc, SSL_CTX *ctx)

engine_args.libctx = ctx->libctx;
engine_args.propq = ctx->propq;
#if defined(OPENSSL_THREADS)
engine_args.mutex = qc->mutex;
#endif
engine_args.now_cb = get_time_cb;
engine_args.now_cb_arg = qc;
qc->engine = ossl_quic_engine_new(&engine_args);
Expand Down Expand Up @@ -4041,7 +4045,9 @@ SSL *ossl_quic_new_listener(SSL_CTX *ctx, uint64_t flags)

engine_args.libctx = ctx->libctx;
engine_args.propq = ctx->propq;
#if defined(OPENSSL_THREADS)
engine_args.mutex = ql->mutex;
#endif
if ((ql->engine = ossl_quic_engine_new(&engine_args)) == NULL) {
QUIC_RAISE_NON_NORMAL_ERROR(NULL, ERR_R_INTERNAL_ERROR, NULL);
goto err;
Expand Down Expand Up @@ -4070,6 +4076,9 @@ SSL *ossl_quic_new_listener(SSL_CTX *ctx, uint64_t flags)
if (ql != NULL)
ossl_quic_engine_free(ql->engine);

#if defined(OPENSSL_THREADS)
ossl_crypto_mutex_free(&ql->mutex);
#endif
OPENSSL_free(ql);
return NULL;
}
Expand Down Expand Up @@ -4187,7 +4196,9 @@ static QUIC_CONNECTION *create_qc_from_incoming_conn(QUIC_LISTENER *ql, QUIC_CHA
qc->engine = ql->engine;
qc->port = ql->port;
qc->ch = ch;
#if defined(OPENSSL_THREADS)
qc->mutex = ql->mutex;
#endif
qc->tls = ossl_quic_channel_get0_tls(ch);
qc->last_net_bio_epoch = UINT64_MAX;
qc->started = 1;
Expand Down
4 changes: 4 additions & 0 deletions ssl/quic/quic_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ struct quic_conn_st {
* The mutex used to synchronise access to the QUIC_CHANNEL. We own this but
* provide it to the channel.
*/
#if defined(OPENSSL_THREADS)
CRYPTO_MUTEX *mutex;
#endif

/*
* If we have a default stream attached, this is the internal XSO
Expand Down Expand Up @@ -269,11 +271,13 @@ struct quic_listener_st {
/* The QUIC port representing the QUIC listener and socket. */
QUIC_PORT *port;

#if defined(OPENSSL_THREADS)
/*
* The mutex used to synchronise access to the QUIC_ENGINE. We own this but
* provide it to the engine.
*/
CRYPTO_MUTEX *mutex;
#endif

/* Have we started listening yet? */
unsigned int listening : 1;
Expand Down

0 comments on commit 06ba67d

Please sign in to comment.