From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Willem de Bruijn <willemb@google.com>,
Jakub Kicinski <kuba@kernel.org>, Sasha Levin <sashal@kernel.org>,
jhs@mojatatu.com, jiri@resnulli.us, davem@davemloft.net,
edumazet@google.com, pabeni@redhat.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH AUTOSEL 6.18] net_sched: sch_fq: convert skb->tstamp if not monotonic
Date: Mon, 31 Aug 2026 09:27:08 -0400 [thread overview]
Message-ID: <20260831133314.4125787-400-sashal@kernel.org> (raw)
In-Reply-To: <20260831133314.4125787-1-sashal@kernel.org>
From: Willem de Bruijn <willemb@google.com>
[ Upstream commit c4f796c4f16ba375b43c608d6bd0f72e20168312 ]
FQ currently assumes skb->tstamp holds monotonic time, as used by TCP.
Users with ns_capable CAP_NET_ADMIN can transmit skbs using SO_TXTIME
with CLOCK_MONOTONIC, CLOCK_REALTIME or CLOCK_TAI clockids as of
commit 80b14dee2bea ("net: Add a new socket option for a future
transmit time.")
More recently, skbs also gained tstamp_type to explicitly communicate
the clockid of skb->tstamp, with commit 4d25ca2d6801 ("net: Rename
mono_delivery_time to tstamp_type for scalabilty"), commit
1693c5db6ab8 ("net: Add additional bit to support clockid_t timestamp
type") and a few others.
Detect other clocks and convert to monotonic for use in FQ. That is,
convert fq_skb_cb(skb)->time_to_send. Do not convert skb->tstamp
itself. Network device clocks are more commonly synchronized to TAI.
Conversion may be imprecise due to clock adjustment (e.g., adjfreq)
between when SCM_TSTAMP is set and when it is converted in fq_enqueue.
The common codepath is short, so skew will be well below common pacing
operation. Even in edge cases, bursts (too soon) or beyond horizon
(too late) are indistinguishable from network conditions. To which
senders must be robust, as long as infrequent.
Avoid overflow due to negative offsets becoming huge when converting
from signed ktime_t to u64 time_to_send. Bound lower to mono 1 and
upper to now + q->horizon. This protects against bad input, e.g.,
from BPF programs.
Detect legacy BPF programs that program skb->tstamp without setting
skb->tstamp_type. Here tstamp_type is zero (SKB_CLOCK_REALTIME), but
the value will be unrealistic for realtime in the 21st century. Follow
existing TIME_UPTIME_SEC_MAX as bound between mono and realtime.
Signed-off-by: Willem de Bruijn <willemb@google.com>
----
Changes
v1 -> v2
- replace Fixes tag with references inside the commit message
Link: https://patch.msgid.link/20260604194221.3319080-3-willemdebruijn.kernel@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
The background searches finished and match what the full analysis
already found:
- **Commit search:** The fix (`fq_skb_tstamp_to_mono`, subject grep) is
**not** in this tree yet (6.18.44). `b4 dig` on `HEAD` wasn’t useful;
using the mainline hash `c4f796c4f16b` did locate the lore thread.
- **Related fixes:** No existing `sch_fq` clock-conversion fix here. The
grep hits are separate forwarding-path cleanups (clearing
`skb->tstamp` in OVS, netfilter, ipvs) — related timestamp handling,
but not this FQ bug.
**Verdict stands: YES** for 6.18.y — FQ still compares monotonic `now`
against unconverted REALTIME/TAI `skb->tstamp`, and with default
`horizon_drop=1` those SO_TXTIME packets get dropped. The patch cherry-
picks cleanly onto 6.18.44.
net/sched/sch_fq.c | 43 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 38 insertions(+), 5 deletions(-)
diff --git a/net/sched/sch_fq.c b/net/sched/sch_fq.c
index 5e41930079948..e4f5a1cb238ff 100644
--- a/net/sched/sch_fq.c
+++ b/net/sched/sch_fq.c
@@ -531,14 +531,44 @@ static void flow_queue_add(struct fq_flow *flow, struct sk_buff *skb)
rb_insert_color(&skb->rbnode, &flow->t_root);
}
-static bool fq_packet_beyond_horizon(const struct sk_buff *skb,
+static bool fq_packet_beyond_horizon(ktime_t time_to_send,
const struct fq_sched_data *q, u64 now)
{
- return unlikely((s64)skb->tstamp > (s64)(now + q->horizon));
+ return unlikely((s64)time_to_send > (s64)(now + q->horizon));
}
#define FQDR(reason) SKB_DROP_REASON_FQ_##reason
+static ktime_t fq_skb_tstamp_to_mono(struct sk_buff *skb)
+{
+ const ktime_t mono_max = NSEC_PER_SEC * TIME_UPTIME_SEC_MAX;
+
+ if (likely(skb->tstamp_type == SKB_CLOCK_MONOTONIC))
+ return max(skb->tstamp, 1);
+
+ if (skb->tstamp_type == SKB_CLOCK_TAI)
+ return max(ktime_sub(skb->tstamp, ktime_mono_to_any(0, TK_OFFS_TAI)), 1);
+
+ if (likely(skb->tstamp > mono_max))
+ return max(ktime_sub(skb->tstamp, ktime_mono_to_real(0)), 1);
+
+ /* Handle BPF programs setting skb->stamp but not tstamp_type */
+ net_warn_ratelimited("fq: likely mono tstamp with tstamp_type 0\n");
+
+ skb->tstamp_type = SKB_CLOCK_MONOTONIC;
+ return max(skb->tstamp, 1);
+}
+
+static void fq_mono_to_skb_tstamp(struct sk_buff *skb, ktime_t time_to_send)
+{
+ if (skb->tstamp_type == SKB_CLOCK_MONOTONIC)
+ skb->tstamp = time_to_send;
+ else if (skb->tstamp_type == SKB_CLOCK_REALTIME)
+ skb->tstamp = ktime_mono_to_real(time_to_send);
+ else
+ skb->tstamp = ktime_mono_to_any(time_to_send, TK_OFFS_TAI);
+}
+
static int fq_enqueue(struct sk_buff *skb, struct Qdisc *sch,
struct sk_buff **to_free)
{
@@ -558,17 +588,20 @@ static int fq_enqueue(struct sk_buff *skb, struct Qdisc *sch,
if (!skb->tstamp) {
fq_skb_cb(skb)->time_to_send = now;
} else {
+ ktime_t time_to_send = fq_skb_tstamp_to_mono(skb);
+
/* Check if packet timestamp is too far in the future. */
- if (fq_packet_beyond_horizon(skb, q, now)) {
+ if (fq_packet_beyond_horizon(time_to_send, q, now)) {
if (q->horizon_drop) {
q->stat_horizon_drops++;
return qdisc_drop_reason(skb, sch, to_free,
FQDR(HORIZON_LIMIT));
}
q->stat_horizon_caps++;
- skb->tstamp = now + q->horizon;
+ time_to_send = now + q->horizon;
+ fq_mono_to_skb_tstamp(skb, time_to_send);
}
- fq_skb_cb(skb)->time_to_send = skb->tstamp;
+ fq_skb_cb(skb)->time_to_send = (u64)time_to_send;
}
f = fq_classify(sch, skb, now);
--
2.53.0
next prev parent reply other threads:[~2026-08-31 13:45 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260831133314.4125787-1-sashal@kernel.org>
2026-08-31 13:20 ` [PATCH AUTOSEL 6.18-6.12] netconsole: take target_cleanup_list_lock in drop_netconsole_target() Sasha Levin
2026-08-31 13:20 ` [PATCH AUTOSEL 6.18-6.6] bridge: Add missing READ_ONCE() annotations around FDB destination port Sasha Levin
2026-08-31 13:20 ` [PATCH AUTOSEL 6.18-6.6] net: phy: motorcomm: use device properties for firmware tuning Sasha Levin
2026-08-31 13:20 ` [PATCH AUTOSEL 6.18-5.15] dpaa2-switch: rework FDB management on the bridge leave path Sasha Levin
2026-08-31 13:21 ` [PATCH AUTOSEL 6.18] net: airoha: Reserve RX headroom to avoid skb reallocation Sasha Levin
2026-08-31 13:21 ` [PATCH AUTOSEL 6.18-6.1] eth: mlx5: fix macsec dependency Sasha Levin
2026-08-31 13:21 ` [PATCH AUTOSEL 6.18-5.10] phonet: check register_netdevice_notifier() error in phonet_device_init() Sasha Levin
2026-08-31 13:21 ` [PATCH AUTOSEL 6.18] net: sfp: apply I2C adapter quirks to limit block size Sasha Levin
2026-08-31 13:21 ` [PATCH AUTOSEL 6.18-5.10] hsr: broadcast netlink notifications in the device's net namespace Sasha Levin
2026-08-31 13:21 ` [PATCH AUTOSEL 6.18-5.10] vhost-scsi: flush backend after device ioctls Sasha Levin
2026-08-31 13:22 ` [PATCH AUTOSEL 6.18-5.10] bridge: Do not suppress ARP probes and DAD NS unconditionally Sasha Levin
2026-08-31 13:22 ` [PATCH AUTOSEL 6.18-5.10] sctp: Unwind address notifier registration on failure Sasha Levin
2026-08-31 13:22 ` [PATCH AUTOSEL 6.18-5.15] ptp: ocp: add shutdown callback Sasha Levin
2026-08-31 13:22 ` [PATCH AUTOSEL 6.18-6.12] net: lan966x: restore RX state on reload failure Sasha Levin
2026-08-31 13:22 ` [PATCH AUTOSEL 6.18-6.6] net/mlx5: E-Switch, align disable sequence with switchdev-to-legacy transition Sasha Levin
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18-6.6] tls: Flush backlog before waiting for a new record Sasha Levin
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18-5.10] net: dsa: sja1105: flower: reject cross-chip redirect Sasha Levin
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18-6.12] net: hns3: improve the unused_tuple parameter setting Sasha Levin
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18-6.1] net: thunderx: fix PTP device ref leak in nicvf_probe() Sasha Levin
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18-5.10] net: stmmac: xgmac2: disable RBUE in default RX interrupt mask Sasha Levin
2026-08-31 13:23 ` [PATCH AUTOSEL 6.18-5.10] ipv6: Honor oif when choosing nexthop for locally generated traffic Sasha Levin
2026-08-31 13:24 ` [PATCH AUTOSEL 6.18-5.10] ipv6: addrconf: fix temp address generation after prefix deprecation Sasha Levin
2026-08-31 13:24 ` [PATCH AUTOSEL 6.18-5.10] net/sched: sch_drr: make cl->quantum lockless Sasha Levin
2026-08-31 13:24 ` [PATCH AUTOSEL 6.18] net: napi: Skip last poll when arming gro timer in busy poll Sasha Levin
2026-08-31 13:24 ` [PATCH AUTOSEL 6.18-5.10] rds: annotate data-race around rs_seen_congestion Sasha Levin
2026-08-31 13:24 ` [PATCH AUTOSEL 6.18-5.10] net: dsa: mv88e6xxx: enable .rmu_disable() for 6320 family Sasha Levin
2026-08-31 13:24 ` [PATCH AUTOSEL 6.18-5.10] net: qrtr: fix node refcount leak on ctrl packet alloc failure Sasha Levin
2026-08-31 13:25 ` [PATCH AUTOSEL 6.18-5.15] dpaa2-switch: fix handling of NAPI on the remove path Sasha Levin
2026-08-31 13:25 ` [PATCH AUTOSEL 6.18-5.15] net: dsa: mv88e6xxx: define .pot_clear() for 6321 Sasha Levin
2026-08-31 13:25 ` [PATCH AUTOSEL 6.18-6.12] net/mlx5e: Verify unique vhca_id count instead of range Sasha Levin
2026-08-31 13:25 ` [PATCH AUTOSEL 6.18-5.10] ice: pass the return value of skb_checksum_help() Sasha Levin
2026-08-31 13:25 ` [PATCH AUTOSEL 6.18-6.12] pds_core: quiesce DMA before freeing resources Sasha Levin
2026-08-31 13:25 ` [PATCH AUTOSEL 6.18-6.12] net/mlx5: HWS, Handle destroying table that has a miss table Sasha Levin
2026-08-31 13:25 ` [PATCH AUTOSEL 6.18-5.10] rds: filter RDS_INFO_* getsockopt by caller's netns Sasha Levin
2026-08-31 13:25 ` [PATCH AUTOSEL 6.18] net: mscc: ocelot: validate netdev belongs to switch in .netdev_to_port() Sasha Levin
2026-08-31 13:25 ` [PATCH AUTOSEL 6.18-5.10] e1000e: limit endianness conversion to boundary words Sasha Levin
2026-08-31 13:26 ` [PATCH AUTOSEL 6.18] net: ethtool: cmis_cdb: hold instance lock for ops locked devices Sasha Levin
2026-08-31 13:26 ` [PATCH AUTOSEL 6.18-5.10] net: au1000: move free_irq out of the close-time spinlocked section Sasha Levin
2026-08-31 13:26 ` [PATCH AUTOSEL 6.18-5.10] vsock: use sk_acceptq_is_full() helper in all transports Sasha Levin
2026-08-31 13:26 ` [PATCH AUTOSEL 6.18-6.1] net: dsa: realtek: rtl8365mb: add support for RTL8367SB Sasha Levin
2026-08-31 13:26 ` [PATCH AUTOSEL 6.18-6.12] rtase: Fix flow control configuration Sasha Levin
2026-08-31 13:26 ` [PATCH AUTOSEL 6.18-5.15] dpaa2-switch: fix the error path in dpaa2_switch_rx() Sasha Levin
2026-08-31 13:27 ` [PATCH AUTOSEL 6.18-6.12] ipv6: use READ_ONCE() for bindv6only default in inet6_create() Sasha Levin
2026-08-31 13:27 ` Sasha Levin [this message]
2026-08-31 13:27 ` [PATCH AUTOSEL 6.18] net/mlx5: HWS, Check if device is down while polling for completion Sasha Levin
2026-08-31 13:27 ` [PATCH AUTOSEL 6.18-6.6] net: microchip: sparx5: clean up PSFP resources on flower setup failure Sasha Levin
2026-08-31 13:27 ` [PATCH AUTOSEL 6.18-5.10] xfrm: allow migration from UDP encapsulated to non-encapsulated ESP Sasha Levin
2026-09-01 7:50 ` Antony Antony
2026-09-01 9:14 ` Sabrina Dubroca
2026-09-01 15:08 ` Sasha Levin
2026-08-31 13:27 ` [PATCH AUTOSEL 6.18] net: phy: sfp: detect presence via I2C when no MOD_DEF0 GPIO Sasha Levin
2026-08-31 13:27 ` [PATCH AUTOSEL 6.18-5.10] netlabel: fix IPv6 unlabeled address add error handling Sasha Levin
2026-08-31 13:27 ` [PATCH AUTOSEL 6.18-6.12] net: mana: hardening: Reject zero max_num_queues from MANA_QUERY_VPORT_CONFIG Sasha Levin
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18-5.10] net: ibm: emac: Reserve VLAN header in MJS limit Sasha Levin
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18-6.1] net: wwan: t7xx: Add delay between MD and SAP suspend Sasha Levin
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18-6.12] net: sfp: add quirk for OEM 2.5G optical modules Sasha Levin
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18-6.1] net: phy: sfp: probe for RollBall I2C-to-MDIO bridge in mdio-i2c Sasha Levin
2026-09-01 5:28 ` Petr Wozniak
2026-09-01 15:07 ` Sasha Levin
[not found] ` <CALSZ6VYWSva6FY-40n8f-eeinu5qXkPbwXue9N9+=D7iEL+ksg@mail.gmail.com>
2026-09-01 15:07 ` Sasha Levin
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18-5.10] net/sched: act_csum: don't mangle UDP tunnel GSO packets Sasha Levin
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18] net/mlx5: Relax capability check for eswitch query paths Sasha Levin
2026-08-31 13:28 ` [PATCH AUTOSEL 6.18] psp: validate IPv4 header fields in psp_dev_rcv() Sasha Levin
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18-5.10] net/rds: Don't sleep inside rds_ib_conn_path_shutdown Sasha Levin
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18-5.10] netfilter: nf_conntrack_expect: zero at allocation time Sasha Levin
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18] net: sfp: extend SMBus support Sasha Levin
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18] bpf, sockmap: reject a packet-modifying SK_SKB stream parser Sasha Levin
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18-6.1] net: hsr: require valid EOT supervision TLV Sasha Levin
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18-5.10] net: bridge: remove stale rcu_barrier() in br_multicast_dev_del() Sasha Levin
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18] net: txgbe: fix phylink leak on AML init failure Sasha Levin
2026-08-31 13:29 ` [PATCH AUTOSEL 6.18] net/mlx5: Switch vport HCA cap helpers to kvzalloc Sasha Levin
2026-08-31 13:30 ` [PATCH AUTOSEL 6.18-5.10] netfilter: ipset: mark the rcu locked areas properly Sasha Levin
2026-08-31 13:30 ` [PATCH AUTOSEL 6.18-5.10] xprtrdma: Add request-pool slack for delayed recycling Sasha Levin
2026-08-31 13:30 ` [PATCH AUTOSEL 6.18] netfilter: nf_tables: use DEBUG_NET_WARN_ON_ONCE in packet and control paths Sasha Levin
2026-08-31 13:30 ` [PATCH AUTOSEL 6.18-6.1] tls: reject the combination of TLS and sockmap Sasha Levin
2026-09-01 9:36 ` Sabrina Dubroca
2026-09-01 15:09 ` Sasha Levin
2026-09-02 15:35 ` Sabrina Dubroca
2026-08-31 13:30 ` [PATCH AUTOSEL 6.18-5.10] netfilter: nf_conntrack: use get_unaligned_be32() in tcp_sack() Sasha Levin
2026-08-31 13:30 ` [PATCH AUTOSEL 6.18-5.10] net: usb: qmi_wwan: add MeiG SRM813Q Sasha Levin
2026-08-31 13:30 ` [PATCH AUTOSEL 6.18-5.10] net: cpsw_new: unregister devlink on port registration failure Sasha Levin
2026-08-31 13:30 ` [PATCH AUTOSEL 6.18] net: ibm: emac: fix unchecked platform_get_irq return value Sasha Levin
2026-08-31 13:31 ` [PATCH AUTOSEL 6.18-5.10] net: ibm: emac: mal: fix potential system hang in mal_remove() Sasha Levin
2026-08-31 13:31 ` [PATCH AUTOSEL 6.18-5.15] netfilter: nfnetlink_log: wait for rcu grace period before freeing pernet state Sasha Levin
2026-08-31 13:31 ` [PATCH AUTOSEL 6.18-6.6] net: dsa: qca8k: Add support for force mode for fixed link topology Sasha Levin
2026-08-31 13:31 ` [PATCH AUTOSEL 6.18] net: ibm: emac: mal: fix unchecked platform_get_irq return values Sasha Levin
2026-08-31 13:31 ` [PATCH AUTOSEL 6.18-5.10] net: dsa: mv88e6xxx: fix number of g1 interrupts for 6320 family Sasha Levin
2026-08-31 13:31 ` [PATCH AUTOSEL 6.18] net: ensure SCM_TXTIME delivery time is no older than system boot Sasha Levin
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=20260831133314.4125787-400-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=willemb@google.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