From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FEC43BF31F for ; Thu, 15 Jan 2026 17:12:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497154; cv=none; b=DsuMrcSUidXEIGbWbpJNUzrr1WMl3/r98oJzr/L4QJUG+hdpfWL9Ioy7i5ce3ILNDtxDjVaZco5lfsRsZ/8gP1EWH7sHu/gkSbe9eAVxLgAnDALjf0sULx0vAPp2ajSTwwwDNq7Eg1J5uD5VV3IAmBj+wn74jhhV7c3eVwLRJL4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497154; c=relaxed/simple; bh=JJqkpuUFuIe/gFYva1ohWTEXB+T9x5tVlAQa7/2p+6k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J+F1cFNe1/CmbPGGvCW83GZabTspI5Fr2RDCOgRZxptDarxD1/1J2RY+7+8m+C8n1pLYm1eduyuJIU7mKLepK7x1t+nMIV0gw/BX4lnGrPMg8hxRpE6IOLlkspyApAHlib8hxX1DmfPQKySkrWcxDE7EqkP2b9m4kOltB0MO4TQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jvGruGfl; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jvGruGfl" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-81df6a302b1so1030401b3a.2 for ; Thu, 15 Jan 2026 09:12:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768497151; x=1769101951; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tYFKy8wmeOF9/xLY0YwTs32UNcdqHUMzReGDert9fzo=; b=jvGruGflQdvsZGFC1oZplYqxEwlVooXX8Ihpau7pZGyYfjGXRL9hVKFZYtHpqtYXX0 Aeqs/3Q6iktJeAP8OM/2jP3w0Y9dIc6UXYDcGoBYRk34pC2pPCBuYbnto3eCZAvHM8m9 19w2NviEXXKLWTYgLgZxKq5rZtV7CByVaZRVaJGIL3IuwBDxwof+2kxv9fT4QmNQ2Eqq KyAvaIoEInUfFqBYLxyfiCc171QZKJu3VkU9C6cFhpcwwBGuqLlmCSW7xNzbd13xXp8V 3N79NFWW8kT7s98LxiPXSz3HNuLdZbhEsTbzaRDWjDPnOnhP/RyFu4MdBPC5XXUOZZig nFFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768497151; x=1769101951; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=tYFKy8wmeOF9/xLY0YwTs32UNcdqHUMzReGDert9fzo=; b=qa8vW+p622POzUL+rTEONGhG5PFLOWT1F6vyOTEN8YXzwpnUZHfraT09iiahmiDD1l krrdzBOD6TOf7i7KBCgc77r2OzOLLeUYJNjmqbjSCr/IsJRuYTVnDkLUMxSC/1jrILvR W7iGpXpr0MhEmHSWlFhc41ZRWW4BAmT9+dduWs1EK6bheNqNgJo1spZRT/0izm1swwG/ RE2ov2vKKn/spKCLjZpUkSssQqB73g+Z2l8Yu64X1vo/SQ37okAnUKyt2hfjKI9WCh41 13QWQUMRppNghMxzNIK+nbhoHSV6bx+I7o8cW/cWjZTQmoSYdZStN5BjkeZg/RIOCLqX xZAw== X-Forwarded-Encrypted: i=1; AJvYcCW1cePzMys7JcquJTfuYPtPaQqWY9f91N4toAdXEDIFzlR5+L6XLLoP4j03YMn57qXL/hcG@lists.linux.dev X-Gm-Message-State: AOJu0YwnLWAf4xJ5sZvPopk4uHH+8B8wNYjd9cHVJ+JvSPEZ/oCF9Via 5V9GdijjU4sltTJT6lXnYORrgDWV6ZXIzym0pCVjQ94oSS+rakaQXBoThbRq1hNr X-Gm-Gg: AY/fxX4AYXGl34vWDKEEwHgW2dvb6c37EafZZr6fv08yw+H7TOBvsk9lgTIWhYRhmAK JOdZypvl6rrD2SugV7UJzydmj5JLXs3Emcla9vMfHa6VdR5QHI73nj3a1xZiSFWdUeBoZ/261jR hQnBgyxzPG6Ar97zg6InHolpRh0m7YontA6UNJ28zs61SO5pLsEQsd1XVzNm9duzStfL6WImV2X DpBmAIFh266hRxlCDN2CANaggavadxt4sQ3fbP0C30xRx63U902BSl3BaUAziLFW3o1eyoixxs0 VSuH7RMGJAAUnIthwDYXlNpiJjoH0qwN8IVYal0HqoknPsF7x+qPNUyX2ZBg2YLfTh9PQmIL1Gv nSmeule186L5kQV9X2lbC82ttfA6TzL2FY36mC0m1J9Z6pR2PvztVciGaJZcmpPBUeVEBxHuo/G 1QS7hkad7ioG9MVbJQW+OsT/oIz4PWgYIh6bTOEawWpO4hrEfykQC1U4JU0T1DsA== X-Received: by 2002:a05:6214:d49:b0:880:4c2d:dc8c with SMTP id 6a1803df08f44-89274384cf2mr83259406d6.18.1768490228405; Thu, 15 Jan 2026 07:17:08 -0800 (PST) Received: from wsfd-netdev58.anl.eng.rdu2.dc.redhat.com ([66.187.232.140]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-890770cc6edsm201030056d6.4.2026.01.15.07.16.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jan 2026 07:17:07 -0800 (PST) From: Xin Long To: network dev , quic@lists.linux.dev Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Paolo Abeni , Simon Horman , Stefan Metzmacher , Moritz Buhl , Tyler Fanelli , Pengtao He , Thomas Dreibholz , linux-cifs@vger.kernel.org, Steve French , Namjae Jeon , Paulo Alcantara , Tom Talpey , kernel-tls-handshake@lists.linux.dev, Chuck Lever , Jeff Layton , Steve Dickson , Hannes Reinecke , Alexander Aring , David Howells , Matthieu Baerts , John Ericson , Cong Wang , "D . Wythe" , Jason Baron , illiliti , Sabrina Dubroca , Marcelo Ricardo Leitner , Daniel Stenberg , Andy Gospodarek Subject: [PATCH net-next v7 13/16] quic: add timer management Date: Thu, 15 Jan 2026 10:11:13 -0500 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: quic@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This patch introduces 'quic_timer' to unify and manage the five main timers used in QUIC: loss detection, delayed ACK, path validation, PMTU probing, and pacing. These timers are critical for driving retransmissions, connection liveness, and flow control. Each timer type is initialized, started, reset, or stopped using a common set of operations. - quic_timer_reset(): Reset a timer with type and timeout - quic_timer_start(): Start a timer with type and timeout - quic_timer_stop(): Stop a timer with type Although handler functions for each timer are defined, they are currently placeholders; their logic will be implemented in upcoming patches for packet transmission and outqueue handling. Deferred timer actions are also integrated through quic_release_cb(), which dispatches to the appropriate handler when timers expire. Signed-off-by: Tyler Fanelli Signed-off-by: Xin Long Acked-by: Paolo Abeni --- v5: - Rename QUIC_TSQ_DEFERRED to QUIC_PACE_DEFERRED. --- net/quic/Makefile | 2 +- net/quic/socket.c | 33 ++++++++ net/quic/socket.h | 33 ++++++++ net/quic/timer.c | 196 ++++++++++++++++++++++++++++++++++++++++++++++ net/quic/timer.h | 47 +++++++++++ 5 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 net/quic/timer.c create mode 100644 net/quic/timer.h diff --git a/net/quic/Makefile b/net/quic/Makefile index 58bb18f7926d..2ccf01ad9e22 100644 --- a/net/quic/Makefile +++ b/net/quic/Makefile @@ -6,4 +6,4 @@ obj-$(CONFIG_IP_QUIC) += quic.o quic-y := common.o family.o protocol.o socket.o stream.o connid.o path.o \ - cong.o pnspace.o crypto.o + cong.o pnspace.o crypto.o timer.o diff --git a/net/quic/socket.c b/net/quic/socket.c index 7fd6955824bc..dde1d9becf06 100644 --- a/net/quic/socket.c +++ b/net/quic/socket.c @@ -47,6 +47,8 @@ static int quic_init_sock(struct sock *sk) quic_conn_id_set_init(quic_dest(sk), 0); quic_cong_init(quic_cong(sk)); + quic_timer_init(sk); + if (quic_stream_init(quic_streams(sk))) return -ENOMEM; @@ -68,6 +70,8 @@ static void quic_destroy_sock(struct sock *sk) { u8 i; + quic_timer_free(sk); + for (i = 0; i < QUIC_PNSPACE_MAX; i++) quic_pnspace_free(quic_pnspace(sk, i)); for (i = 0; i < QUIC_CRYPTO_MAX; i++) @@ -194,6 +198,35 @@ static int quic_getsockopt(struct sock *sk, int level, int optname, static void quic_release_cb(struct sock *sk) { + /* Similar to tcp_release_cb(). */ + unsigned long nflags, flags = smp_load_acquire(&sk->sk_tsq_flags); + + do { + if (!(flags & QUIC_DEFERRED_ALL)) + return; + nflags = flags & ~QUIC_DEFERRED_ALL; + } while (!try_cmpxchg(&sk->sk_tsq_flags, &flags, nflags)); + + if (flags & QUIC_F_LOSS_DEFERRED) { + quic_timer_loss_handler(sk); + __sock_put(sk); + } + if (flags & QUIC_F_SACK_DEFERRED) { + quic_timer_sack_handler(sk); + __sock_put(sk); + } + if (flags & QUIC_F_PATH_DEFERRED) { + quic_timer_path_handler(sk); + __sock_put(sk); + } + if (flags & QUIC_F_PMTU_DEFERRED) { + quic_timer_pmtu_handler(sk); + __sock_put(sk); + } + if (flags & QUIC_F_PACE_DEFERRED) { + quic_timer_pace_handler(sk); + __sock_put(sk); + } } static int quic_disconnect(struct sock *sk, int flags) diff --git a/net/quic/socket.h b/net/quic/socket.h index fc203eecbb8b..5e9b21430f42 100644 --- a/net/quic/socket.h +++ b/net/quic/socket.h @@ -21,6 +21,7 @@ #include "cong.h" #include "protocol.h" +#include "timer.h" extern struct proto quic_prot; extern struct proto quicv6_prot; @@ -32,6 +33,31 @@ enum quic_state { QUIC_SS_ESTABLISHED = TCP_ESTABLISHED, }; +enum quic_tsq_enum { + QUIC_MTU_REDUCED_DEFERRED, + QUIC_LOSS_DEFERRED, + QUIC_SACK_DEFERRED, + QUIC_PATH_DEFERRED, + QUIC_PMTU_DEFERRED, + QUIC_PACE_DEFERRED, +}; + +enum quic_tsq_flags { + QUIC_F_MTU_REDUCED_DEFERRED = BIT(QUIC_MTU_REDUCED_DEFERRED), + QUIC_F_LOSS_DEFERRED = BIT(QUIC_LOSS_DEFERRED), + QUIC_F_SACK_DEFERRED = BIT(QUIC_SACK_DEFERRED), + QUIC_F_PATH_DEFERRED = BIT(QUIC_PATH_DEFERRED), + QUIC_F_PMTU_DEFERRED = BIT(QUIC_PMTU_DEFERRED), + QUIC_F_PACE_DEFERRED = BIT(QUIC_PACE_DEFERRED), +}; + +#define QUIC_DEFERRED_ALL (QUIC_F_MTU_REDUCED_DEFERRED | \ + QUIC_F_LOSS_DEFERRED | \ + QUIC_F_SACK_DEFERRED | \ + QUIC_F_PATH_DEFERRED | \ + QUIC_F_PMTU_DEFERRED | \ + QUIC_F_PACE_DEFERRED) + struct quic_sock { struct inet_sock inet; struct list_head reqs; @@ -48,6 +74,8 @@ struct quic_sock { struct quic_cong cong; struct quic_pnspace space[QUIC_PNSPACE_MAX]; struct quic_crypto crypto[QUIC_CRYPTO_MAX]; + + struct quic_timer timers[QUIC_TIMER_MAX]; }; struct quic6_sock { @@ -125,6 +153,11 @@ static inline struct quic_crypto *quic_crypto(const struct sock *sk, u8 level) return &quic_sk(sk)->crypto[level]; } +static inline void *quic_timer(const struct sock *sk, u8 type) +{ + return (void *)&quic_sk(sk)->timers[type]; +} + static inline bool quic_is_establishing(struct sock *sk) { return sk->sk_state == QUIC_SS_ESTABLISHING; diff --git a/net/quic/timer.c b/net/quic/timer.c new file mode 100644 index 000000000000..6f957385a341 --- /dev/null +++ b/net/quic/timer.c @@ -0,0 +1,196 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* QUIC kernel implementation + * (C) Copyright Red Hat Corp. 2023 + * + * This file is part of the QUIC kernel implementation + * + * Initialization/cleanup for QUIC protocol support. + * + * Written or modified by: + * Xin Long + */ + +#include "socket.h" + +void quic_timer_sack_handler(struct sock *sk) +{ +} + +static void quic_timer_sack_timeout(struct timer_list *t) +{ + struct quic_sock *qs = container_of(t, struct quic_sock, timers[QUIC_TIMER_SACK].t); + struct sock *sk = &qs->inet.sk; + + bh_lock_sock(sk); + if (sock_owned_by_user(sk)) { + if (!test_and_set_bit(QUIC_SACK_DEFERRED, &sk->sk_tsq_flags)) + sock_hold(sk); + goto out; + } + + quic_timer_sack_handler(sk); +out: + bh_unlock_sock(sk); + sock_put(sk); +} + +void quic_timer_loss_handler(struct sock *sk) +{ +} + +static void quic_timer_loss_timeout(struct timer_list *t) +{ + struct quic_sock *qs = container_of(t, struct quic_sock, timers[QUIC_TIMER_LOSS].t); + struct sock *sk = &qs->inet.sk; + + bh_lock_sock(sk); + if (sock_owned_by_user(sk)) { + if (!test_and_set_bit(QUIC_LOSS_DEFERRED, &sk->sk_tsq_flags)) + sock_hold(sk); + goto out; + } + + quic_timer_loss_handler(sk); +out: + bh_unlock_sock(sk); + sock_put(sk); +} + +void quic_timer_path_handler(struct sock *sk) +{ +} + +static void quic_timer_path_timeout(struct timer_list *t) +{ + struct quic_sock *qs = container_of(t, struct quic_sock, timers[QUIC_TIMER_PATH].t); + struct sock *sk = &qs->inet.sk; + + bh_lock_sock(sk); + if (sock_owned_by_user(sk)) { + if (!test_and_set_bit(QUIC_PATH_DEFERRED, &sk->sk_tsq_flags)) + sock_hold(sk); + goto out; + } + + quic_timer_path_handler(sk); +out: + bh_unlock_sock(sk); + sock_put(sk); +} + +void quic_timer_reset_path(struct sock *sk) +{ + struct quic_cong *cong = quic_cong(sk); + u64 timeout = cong->pto * 2; + + /* Calculate timeout based on cong.pto, but enforce a lower bound. */ + if (timeout < QUIC_MIN_PATH_TIMEOUT) + timeout = QUIC_MIN_PATH_TIMEOUT; + quic_timer_reset(sk, QUIC_TIMER_PATH, timeout); +} + +void quic_timer_pmtu_handler(struct sock *sk) +{ +} + +static void quic_timer_pmtu_timeout(struct timer_list *t) +{ + struct quic_sock *qs = container_of(t, struct quic_sock, timers[QUIC_TIMER_PMTU].t); + struct sock *sk = &qs->inet.sk; + + bh_lock_sock(sk); + if (sock_owned_by_user(sk)) { + if (!test_and_set_bit(QUIC_PMTU_DEFERRED, &sk->sk_tsq_flags)) + sock_hold(sk); + goto out; + } + + quic_timer_pmtu_handler(sk); +out: + bh_unlock_sock(sk); + sock_put(sk); +} + +void quic_timer_pace_handler(struct sock *sk) +{ +} + +static enum hrtimer_restart quic_timer_pace_timeout(struct hrtimer *hr) +{ + struct quic_sock *qs = container_of(hr, struct quic_sock, timers[QUIC_TIMER_PACE].hr); + struct sock *sk = &qs->inet.sk; + + bh_lock_sock(sk); + if (sock_owned_by_user(sk)) { + if (!test_and_set_bit(QUIC_PACE_DEFERRED, &sk->sk_tsq_flags)) + sock_hold(sk); + goto out; + } + + quic_timer_pace_handler(sk); +out: + bh_unlock_sock(sk); + sock_put(sk); + return HRTIMER_NORESTART; +} + +void quic_timer_reset(struct sock *sk, u8 type, u64 timeout) +{ + struct timer_list *t = quic_timer(sk, type); + + if (timeout && !mod_timer(t, jiffies + usecs_to_jiffies(timeout))) + sock_hold(sk); +} + +void quic_timer_start(struct sock *sk, u8 type, u64 timeout) +{ + struct timer_list *t; + struct hrtimer *hr; + + if (type == QUIC_TIMER_PACE) { + hr = quic_timer(sk, type); + + if (!hrtimer_is_queued(hr)) { + hrtimer_start(hr, ns_to_ktime(timeout), HRTIMER_MODE_ABS_PINNED_SOFT); + sock_hold(sk); + } + return; + } + + t = quic_timer(sk, type); + if (timeout && !timer_pending(t)) { + if (!mod_timer(t, jiffies + usecs_to_jiffies(timeout))) + sock_hold(sk); + } +} + +void quic_timer_stop(struct sock *sk, u8 type) +{ + if (type == QUIC_TIMER_PACE) { + if (hrtimer_try_to_cancel(quic_timer(sk, type)) == 1) + sock_put(sk); + return; + } + if (timer_delete(quic_timer(sk, type))) + sock_put(sk); +} + +void quic_timer_init(struct sock *sk) +{ + timer_setup(quic_timer(sk, QUIC_TIMER_LOSS), quic_timer_loss_timeout, 0); + timer_setup(quic_timer(sk, QUIC_TIMER_SACK), quic_timer_sack_timeout, 0); + timer_setup(quic_timer(sk, QUIC_TIMER_PATH), quic_timer_path_timeout, 0); + timer_setup(quic_timer(sk, QUIC_TIMER_PMTU), quic_timer_pmtu_timeout, 0); + /* Use hrtimer for pace timer, ensuring precise control over send timing. */ + hrtimer_setup(quic_timer(sk, QUIC_TIMER_PACE), quic_timer_pace_timeout, + CLOCK_MONOTONIC, HRTIMER_MODE_ABS_PINNED_SOFT); +} + +void quic_timer_free(struct sock *sk) +{ + quic_timer_stop(sk, QUIC_TIMER_LOSS); + quic_timer_stop(sk, QUIC_TIMER_SACK); + quic_timer_stop(sk, QUIC_TIMER_PATH); + quic_timer_stop(sk, QUIC_TIMER_PMTU); + quic_timer_stop(sk, QUIC_TIMER_PACE); +} diff --git a/net/quic/timer.h b/net/quic/timer.h new file mode 100644 index 000000000000..61b094325334 --- /dev/null +++ b/net/quic/timer.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* QUIC kernel implementation + * (C) Copyright Red Hat Corp. 2023 + * + * This file is part of the QUIC kernel implementation + * + * Written or modified by: + * Xin Long + */ + +enum { + QUIC_TIMER_LOSS, /* Loss detection timer: triggers retransmission on packet loss */ + QUIC_TIMER_SACK, /* ACK delay timer, also used as idle timer alias */ + QUIC_TIMER_PATH, /* Path validation timer: verifies network path connectivity */ + QUIC_TIMER_PMTU, /* Packetization Layer Path MTU Discovery probing timer */ + QUIC_TIMER_PACE, /* Pacing timer: controls packet transmission pacing */ + QUIC_TIMER_MAX, + QUIC_TIMER_IDLE = QUIC_TIMER_SACK, +}; + +struct quic_timer { + union { + struct timer_list t; + struct hrtimer hr; + }; +}; + +#define QUIC_MIN_PROBE_TIMEOUT 5000000 + +#define QUIC_MIN_PATH_TIMEOUT 1500000 + +#define QUIC_MIN_IDLE_TIMEOUT 1000000 +#define QUIC_DEF_IDLE_TIMEOUT 30000000 + +void quic_timer_reset(struct sock *sk, u8 type, u64 timeout); +void quic_timer_start(struct sock *sk, u8 type, u64 timeout); +void quic_timer_stop(struct sock *sk, u8 type); +void quic_timer_init(struct sock *sk); +void quic_timer_free(struct sock *sk); + +void quic_timer_reset_path(struct sock *sk); + +void quic_timer_loss_handler(struct sock *sk); +void quic_timer_pace_handler(struct sock *sk); +void quic_timer_path_handler(struct sock *sk); +void quic_timer_sack_handler(struct sock *sk); +void quic_timer_pmtu_handler(struct sock *sk); -- 2.47.1