net: mark skb NAPI IDs independently of busy polling
Subsystems (8)
PATCH 1/1 net: mark skb NAPI IDs independently of busy polling
Commit 97dc7cd92ac6 ("ptp: Support late timestamp determination") added support for deferring RX timestamp conversion to ndo_get_tstamp(). When the timestamp is consumed, get_timestamp() uses the skb's NAPI ID to find the device that owns the timestamp cookie and invoke its callback.
Commit e68b6e50fa35 ("udp: enable busy polling for all sockets") gated NAPI ID bookkeeping with CONFIG_NET_RX_BUSY_POLL. As a result, when busy polling is disabled, the skb may not carry a usable NAPI ID. The device lookup then fails, so the driver callback is not invoked. get_timestamp() falls back to hwtstamp, which does not contain the converted timestamp, resulting in an incorrect RX hardware timestamp.
Record skb NAPI IDs independently of busy-poll support to support drivers that use deferred timestamp conversion and future driver features that need to look up a device by its NAPI ID.
---
In the discussion of the issue reported at
https://lore.kernel.org/netdev/[email protected]/
this previous patch added an igc-specific fallback for configurations with CONFIG_NET_RX_BUSY_POLL disabled. It populated skb's hwtstamp field with a timestamp converted using the default hardware timer, allowing get_timestamp() to return it without invoking ndo_get_tstamp(). But Jakub Kicinski noted that the proposed fix appeared to be a driver-specific workaround for a generic problem. The engleder driver would also be affected by the same issue.
This patch introduces a new configuration option to enable NAPI ID bookkeeping independently of busy polling. The option is enabled whenever busy polling is enabled, preserving the existing behavior. It is also selected by the igc and engleder drivers, ensuring that skbs carry a NAPI ID even when busy polling is disabled.
Another approach considered was to require drivers using deferred timestamp conversion, such as igc and engleder, to enable busy polling. However, this would introduce an unnecessary dependency between two independent features: hardware timestamp reporting should not require busy polling to be enabled.
Timestamping has been tested only with igc; it has not been tested with engleder.
Documentation/networking/timestamping.rst | 11 ++++++++--- drivers/net/ethernet/engleder/Kconfig | 1 + drivers/net/ethernet/intel/Kconfig | 1 + include/linux/skbuff.h | 4 ++-- include/net/busy_poll.h | 2 +- include/trace/events/net.h | 2 +- net/Kconfig | 4 ++++ net/core/filter.c | 2 +- net/core/skbuff.c | 2 +- 9 files changed, 20 insertions(+), 9 deletions(-)
Documentation/networking/timestamping.rst +8 -3
@@ -278,9 +278,14 @@ SOF_TIMESTAMPING_OPT_PKTINFO: packets with hardware timestamps. The message contains struct scm_ts_pktinfo, which supplies the index of the real interface which received the packet and its length at layer 2. A valid (non-zero) - interface index will be returned only if CONFIG_NET_RX_BUSY_POLL is - enabled and the driver is using NAPI. The struct contains also two - other fields, but they are reserved and undefined. + interface index will be returned only if CONFIG_SKB_MARK_NAPI_ID is + enabled and the driver is using NAPI. This hidden configuration is + selected automatically by busy-poll support and by drivers that need + skb NAPI IDs to resolve deferred hardware timestamps. Drivers that + use deferred timestamp conversion must select it so the networking + stack can find the device and call its timestamp callback even when + busy polling is disabled. The struct contains also two other fields, + but they are reserved and undefined. SOF_TIMESTAMPING_OPT_TX_SWHW: Request both hardware and software timestamps for outgoing packets
drivers/net/ethernet/engleder/Kconfig +1 -0
@@ -22,6 +22,7 @@ config TSNEP depends on PTP_1588_CLOCK_OPTIONAL select PHYLIB select PAGE_POOL + select SKB_MARK_NAPI_ID help Support for the Engleder TSN endpoint Ethernet MAC IP Core.
drivers/net/ethernet/intel/Kconfig +1 -0
@@ -376,6 +376,7 @@ config IGC depends on PCI depends on PTP_1588_CLOCK_OPTIONAL depends on ETHTOOL_NETLINK + select SKB_MARK_NAPI_ID help This driver supports Intel(R) Ethernet Controller I225-LM/I225-V family of adapters.
include/linux/skbuff.h +2 -2
@@ -1059,7 +1059,7 @@ struct sk_buff {__u16 vlan_tci; }; }; -#if defined(CONFIG_NET_RX_BUSY_POLL) || defined(CONFIG_XPS) +#if defined(CONFIG_SKB_MARK_NAPI_ID) || defined(CONFIG_XPS) union { unsigned int napi_id; unsigned int sender_cpu;
@@ -1267,7 +1267,7 @@ static inline bool skb_pkt_type_ok(u32 ptype)*/ static inline unsigned int skb_napi_id (const struct sk_buff *skb) { -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID return skb->napi_id;#else return 0 ;
include/net/busy_poll.h +1 -1
@@ -130,7 +130,7 @@ static inline void sk_busy_loop(struct sock *sk, int nonblock)static inline void __skb_mark_napi_id (struct sk_buff *skb,const struct gro_node *gro) { -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID /* If the skb was already marked with a valid NAPI ID, avoid overwriting * it. */
include/trace/events/net.h +1 -1
@@ -208,7 +208,7 @@ DECLARE_EVENT_CLASS(net_dev_rx_verbose_template,TP_fast_assign ( __assign_str(name); -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID __entry->napi_id =napi_id_valid (skb->napi_id) ? skb->napi_id :0 ;#else
net/Kconfig +4 -0
@@ -346,9 +346,13 @@ config CGROUP_NET_CLASSID Cgroup subsystem for use as general purpose socket classid marker that is being used in cls_cgroup and for netfilter matching. +config SKB_MARK_NAPI_ID + bool + config NET_RX_BUSY_POLL bool default y if !PREEMPT_RT || (PREEMPT_RT && !NETCONSOLE) + select SKB_MARK_NAPI_ID config BQL bool
net/core/filter.c +1 -1
@@ -10274,7 +10274,7 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type,break ;case offsetof(struct __sk_buff , napi_id): -#if defined(CONFIG_NET_RX_BUSY_POLL ) +#if defined(CONFIG_SKB_MARK_NAPI_ID ) *insn++ =BPF_LDX_MEM (BPF_W , si->dst_reg, si->src_reg, bpf_target_off(struct sk_buff, napi_id, 4, target_size));
net/core/skbuff.c +1 -1
@@ -1581,7 +1581,7 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)#ifdef CONFIG_NETWORK_SECMARK CHECK_SKB_FIELD (secmark);#endif -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID CHECK_SKB_FIELD (napi_id);#endif #ifdef CONFIG_XPS
base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e
Signature · 1 line
2.47.3
[email protected]
AI reviewTL;DR: Commit message only: it blames e68b6e50fa35 for gating skb NAPI IDs on busy polling, but that gating predates it; 97dc7cd92ac6 introduced the dependency. Suggests rewording.
Quoted 1 line
net: mark skb NAPI IDs independently of busy polling
TL;DR: Commit message only: it blames e68b6e50fa35 for gating skb NAPI IDs on busy polling, but that gating predates it; 97dc7cd92ac6 introduced the dependency. Suggests rewording.
Quoted 16 lines
net: mark skb NAPI IDs independently of busy polling
Commit
97dc7cd92ac6("ptp: Support late timestamp determination") added support for deferring RX timestamp conversion tondo_get_tstamp(). When the timestamp is consumed,get_timestamp()uses the skb's NAPI ID to find the device that owns the timestamp cookie and invoke its callback.
Commite68b6e50fa35("udp: enable busy polling for all sockets") gated NAPI ID bookkeeping withCONFIG_NET_RX_BUSY_POLL. As a result, when busy polling is disabled, the skb may not carry a usable NAPI ID. The device lookup then fails, so the driver callback is not invoked.get_timestamp()falls back to hwtstamp, which does not contain the converted timestamp, resulting in an incorrect RX hardware timestamp. Record skb NAPI IDs independently of busy-poll support to support drivers that use deferred timestamp conversion and future driver features that need to look up a device by its NAPI ID.
Quoted 2 lines
Signed-off-by Ding Meng <[email protected]>Reviewed-by Florian Bezdeka <[email protected]>
This isn't a bug, but is e68b6e50fa35 the right commit to name here?
Before that commit, __skb_mark_napi_id() / skb_mark_napi_id() was already inside '#ifdef CONFIG_NET_RX_BUSY_POLL' with an empty stub in the #else branch, and struct sk_buff already had napi_id under
'#if defined(CONFIG_NET_RX_BUSY_POLL) || defined(CONFIG_XPS)'. That gating goes back to 8b80cda536ea ("net: rename ll methods to busy-poll").
e68b6e50fa35 only moved the socket-side sk_mark_napi_id() out of the ifdef block and added sk_mark_napi_id_once(). Both act on sk->sk_napi_id, not on the skb.
It is also about six years older than 97dc7cd92ac6, so the message reads as if a later change broke the deferred-timestamp lookup. In fact get_timestamp() has depended on a busy-poll-only skb field (skb_napi_id() returns 0 when CONFIG_NET_RX_BUSY_POLL=n) since 97dc7cd92ac6 added it.
Could the message say that the skb NAPI ID was always busy-poll-only and that 97dc7cd92ac6 started depending on it?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/41989099174
Jacob Keller
Reviewed-byQuoted 37 lines · On 11/5/2026 12:04 AM, [email protected] wrote:
Quoted 1 line
net: mark skb NAPI IDs independently of busy polling
TL;DR: Commit message only: it blames
e68b6e50fa35for gating skb NAPI IDs on busy polling, but that gating predates it;97dc7cd92ac6introduced the dependency. Suggests rewording.Quoted 16 lines
net: mark skb NAPI IDs independently of busy polling
Commit
97dc7cd92ac6("ptp: Support late timestamp determination") added support for deferring RX timestamp conversion tondo_get_tstamp(). When the timestamp is consumed,get_timestamp()uses the skb's NAPI ID to find the device that owns the timestamp cookie and invoke its callback.
Commite68b6e50fa35("udp: enable busy polling for all sockets") gated NAPI ID bookkeeping withCONFIG_NET_RX_BUSY_POLL. As a result, when busy polling is disabled, the skb may not carry a usable NAPI ID. The device lookup then fails, so the driver callback is not invoked.get_timestamp()falls back to hwtstamp, which does not contain the converted timestamp, resulting in an incorrect RX hardware timestamp. Record skb NAPI IDs independently of busy-poll support to support drivers that use deferred timestamp conversion and future driver features that need to look up a device by its NAPI ID.Quoted 2 lines
Signed-off-by Ding Meng <[email protected]>Reviewed-by Florian Bezdeka <[email protected]>This isn't a bug, but is
e68b6e50fa35the right commit to name here?Before that commit,
__skb_mark_napi_id()/skb_mark_napi_id()was already inside '#ifdefCONFIG_NET_RX_BUSY_POLL' with an empty stub in the #else branch, and structsk_buffalready hadnapi_idunder
'#ifdefined(CONFIG_NET_RX_BUSY_POLL)||defined(CONFIG_XPS)'. That gating goes back to8b80cda536ea("net: rename ll methods to busy-poll").
e68b6e50fa35only moved the socket-sidesk_mark_napi_id()out of the ifdef block and addedsk_mark_napi_id_once(). Both act onsk->sk_napi_id, not on the skb.
Quoted 8 lines
It is also about six years older than
97dc7cd92ac6, so the message reads as if a later change broke the deferred-timestamp lookup. In factget_timestamp()has depended on a busy-poll-only skb field (skb_napi_id()returns 0 whenCONFIG_NET_RX_BUSY_POLL=n) since97dc7cd92ac6added it.Could the message say that the skb NAPI ID was always busy-poll-only and that
97dc7cd92ac6started depending on it?
I think the AI is reading a bit much into the commit message. Clearly the bug is that 97dc7cd92ac6 depends on busy polling. The wording could be slightly more precise to not imply that e68b6e50fa35 actually introduced a problem, but I think that is a bit of a nitpick, and not worth a reroll of this work unless something else needs to change.
Quoted 6 lines
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.mdCI run summary: https://github.com/kernel-patches/bpf/actions/runs/41989099174
Quoted 195 lines · Ding Meng
Commit
97dc7cd92ac6("ptp: Support late timestamp determination") added support for deferring RX timestamp conversion tondo_get_tstamp(). When the timestamp is consumed,get_timestamp()uses the skb's NAPI ID to find the device that owns the timestamp cookie and invoke its callback.Commit
e68b6e50fa35("udp: enable busy polling for all sockets") gated NAPI ID bookkeeping withCONFIG_NET_RX_BUSY_POLL. As a result, when busy polling is disabled, the skb may not carry a usable NAPI ID. The device lookup then fails, so the driver callback is not invoked.get_timestamp()falls back to hwtstamp, which does not contain the converted timestamp, resulting in an incorrect RX hardware timestamp.Record skb NAPI IDs independently of busy-poll support to support drivers that use deferred timestamp conversion and future driver features that need to look up a device by its NAPI ID.
Signed-off-by Ding Meng <[email protected]>Reviewed-by Florian Bezdeka <[email protected]>---
In the discussion of the issue reported at
https://lore.kernel.org/netdev/[email protected]/
this previous patch added an igc-specific fallback for configurations withCONFIG_NET_RX_BUSY_POLLdisabled. It populated skb's hwtstamp field with a timestamp converted using the default hardware timer, allowingget_timestamp()to return it without invokingndo_get_tstamp(). But Jakub Kicinski noted that the proposed fix appeared to be a driver-specific workaround for a generic problem. The engleder driver would also be affected by the same issue.This patch introduces a new configuration option to enable NAPI ID bookkeeping independently of busy polling. The option is enabled whenever busy polling is enabled, preserving the existing behavior. It is also selected by the igc and engleder drivers, ensuring that skbs carry a NAPI ID even when busy polling is disabled.
Another approach considered was to require drivers using deferred timestamp conversion, such as igc and engleder, to enable busy polling. However, this would introduce an unnecessary dependency between two independent features: hardware timestamp reporting should not require busy polling to be enabled.
Timestamping has been tested only with igc; it has not been tested with engleder.
Documentation/networking/timestamping.rst | 11 ++++++++--- drivers/net/ethernet/engleder/Kconfig | 1 + drivers/net/ethernet/intel/Kconfig | 1 + include/linux/skbuff.h | 4 ++-- include/net/busy_poll.h | 2 +- include/trace/events/net.h | 2 +- net/Kconfig | 4 ++++ net/core/filter.c | 2 +- net/core/skbuff.c | 2 +- 9 files changed, 20 insertions(+), 9 deletions(-)Documentation/networking/timestamping.rst +8
-3@@ -278,9 +278,14 @@ SOF_TIMESTAMPING_OPT_PKTINFO: packets with hardware timestamps. The message contains struct scm_ts_pktinfo, which supplies the index of the real interface which received the packet and its length at layer 2. A valid (non-zero) - interface index will be returned only if CONFIG_NET_RX_BUSY_POLL is - enabled and the driver is using NAPI. The struct contains also two - other fields, but they are reserved and undefined. + interface index will be returned only if CONFIG_SKB_MARK_NAPI_ID is + enabled and the driver is using NAPI. This hidden configuration is + selected automatically by busy-poll support and by drivers that need + skb NAPI IDs to resolve deferred hardware timestamps. Drivers that + use deferred timestamp conversion must select it so the networking + stack can find the device and call its timestamp callback even when + busy polling is disabled. The struct contains also two other fields, + but they are reserved and undefined. SOF_TIMESTAMPING_OPT_TX_SWHW: Request both hardware and software timestamps for outgoing packetsdrivers/net/ethernet/engleder/Kconfig +1
-0@@ -22,6 +22,7 @@ config TSNEP depends on PTP_1588_CLOCK_OPTIONAL select PHYLIB select PAGE_POOL + select SKB_MARK_NAPI_ID help Support for the Engleder TSN endpoint Ethernet MAC IP Core.drivers/net/ethernet/intel/Kconfig +1
-0@@ -376,6 +376,7 @@ config IGC depends on PCI depends on PTP_1588_CLOCK_OPTIONAL depends on ETHTOOL_NETLINK + select SKB_MARK_NAPI_ID help This driver supports Intel(R) Ethernet Controller I225-LM/I225-V family of adapters.include/linux/skbuff.h +2
-2@@ -1059,7 +1059,7 @@ struct sk_buff {__u16 vlan_tci; }; }; -#if defined(CONFIG_NET_RX_BUSY_POLL) || defined(CONFIG_XPS) +#if defined(CONFIG_SKB_MARK_NAPI_ID) || defined(CONFIG_XPS) union { unsigned int napi_id; unsigned int sender_cpu;@@ -1267,7 +1267,7 @@ static inline bool skb_pkt_type_ok(u32 ptype)*/ static inline unsigned int skb_napi_id (const struct sk_buff *skb) { -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID return skb->napi_id;#else return 0 ;include/net/busy_poll.h +1
-1@@ -130,7 +130,7 @@ static inline void sk_busy_loop(struct sock *sk, int nonblock)static inline void __skb_mark_napi_id (struct sk_buff *skb,const struct gro_node *gro) { -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID /* If the skb was already marked with a valid NAPI ID, avoid overwriting * it. */ include/trace/events/net.h +1
-1@@ -208,7 +208,7 @@ DECLARE_EVENT_CLASS(net_dev_rx_verbose_template,TP_fast_assign ( __assign_str(name); -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID __entry->napi_id =napi_id_valid (skb->napi_id) ? skb->napi_id :0 ;#else net/Kconfig +4
-0@@ -346,9 +346,13 @@ config CGROUP_NET_CLASSID Cgroup subsystem for use as general purpose socket classid marker that is being used in cls_cgroup and for netfilter matching. +config SKB_MARK_NAPI_ID + bool + config NET_RX_BUSY_POLL bool default y if !PREEMPT_RT || (PREEMPT_RT && !NETCONSOLE) + select SKB_MARK_NAPI_ID config BQL boolnet/core/filter.c +1
-1@@ -10274,7 +10274,7 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type,break ;case offsetof(struct __sk_buff , napi_id): -#if defined(CONFIG_NET_RX_BUSY_POLL ) +#if defined(CONFIG_SKB_MARK_NAPI_ID ) *insn++ =BPF_LDX_MEM (BPF_W , si->dst_reg, si->src_reg, bpf_target_off(struct sk_buff, napi_id, 4, target_size));net/core/skbuff.c +1
-1@@ -1581,7 +1581,7 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)#ifdef CONFIG_NETWORK_SECMARK CHECK_SKB_FIELD (secmark);#endif -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID CHECK_SKB_FIELD (napi_id);#endif #ifdef CONFIG_XPS
Quoted 5 lines
base-commit:
d135ab453a7400a34930bdda1ef4bdc8acfac80e--
2.47.3
Are you sure this does not make the preexisting timestamp lifetime issue more pathological? I think it needs to be fixed now as well. It was the last item mentioned by Sashiko in your review if I remember correctly.
Paul
Quoted 212 lines · Paul Moses
Quoted 195 lines · Ding Meng
Commit
97dc7cd92ac6("ptp: Support late timestamp determination") added support for deferring RX timestamp conversion tondo_get_tstamp(). When the timestamp is consumed,get_timestamp()uses the skb's NAPI ID to find the device that owns the timestamp cookie and invoke its callback.Commit
e68b6e50fa35("udp: enable busy polling for all sockets") gated NAPI ID bookkeeping withCONFIG_NET_RX_BUSY_POLL. As a result, when busy polling is disabled, the skb may not carry a usable NAPI ID. The device lookup then fails, so the driver callback is not invoked.get_timestamp()falls back to hwtstamp, which does not contain the converted timestamp, resulting in an incorrect RX hardware timestamp.Record skb NAPI IDs independently of busy-poll support to support drivers that use deferred timestamp conversion and future driver features that need to look up a device by its NAPI ID.
Signed-off-by Ding Meng <[email protected]>Reviewed-by Florian Bezdeka <[email protected]>---
In the discussion of the issue reported at
https://lore.kernel.org/netdev/[email protected]/
this previous patch added an igc-specific fallback for configurations withCONFIG_NET_RX_BUSY_POLLdisabled. It populated skb's hwtstamp field with a timestamp converted using the default hardware timer, allowingget_timestamp()to return it without invokingndo_get_tstamp(). But Jakub Kicinski noted that the proposed fix appeared to be a driver-specific workaround for a generic problem. The engleder driver would also be affected by the same issue.This patch introduces a new configuration option to enable NAPI ID bookkeeping independently of busy polling. The option is enabled whenever busy polling is enabled, preserving the existing behavior. It is also selected by the igc and engleder drivers, ensuring that skbs carry a NAPI ID even when busy polling is disabled.
Another approach considered was to require drivers using deferred timestamp conversion, such as igc and engleder, to enable busy polling. However, this would introduce an unnecessary dependency between two independent features: hardware timestamp reporting should not require busy polling to be enabled.
Timestamping has been tested only with igc; it has not been tested with engleder.
Documentation/networking/timestamping.rst | 11 ++++++++--- drivers/net/ethernet/engleder/Kconfig | 1 + drivers/net/ethernet/intel/Kconfig | 1 + include/linux/skbuff.h | 4 ++-- include/net/busy_poll.h | 2 +- include/trace/events/net.h | 2 +- net/Kconfig | 4 ++++ net/core/filter.c | 2 +- net/core/skbuff.c | 2 +- 9 files changed, 20 insertions(+), 9 deletions(-)Documentation/networking/timestamping.rst +8
-3@@ -278,9 +278,14 @@ SOF_TIMESTAMPING_OPT_PKTINFO: packets with hardware timestamps. The message contains struct scm_ts_pktinfo, which supplies the index of the real interface which received the packet and its length at layer 2. A valid (non-zero) - interface index will be returned only if CONFIG_NET_RX_BUSY_POLL is - enabled and the driver is using NAPI. The struct contains also two - other fields, but they are reserved and undefined. + interface index will be returned only if CONFIG_SKB_MARK_NAPI_ID is + enabled and the driver is using NAPI. This hidden configuration is + selected automatically by busy-poll support and by drivers that need + skb NAPI IDs to resolve deferred hardware timestamps. Drivers that + use deferred timestamp conversion must select it so the networking + stack can find the device and call its timestamp callback even when + busy polling is disabled. The struct contains also two other fields, + but they are reserved and undefined. SOF_TIMESTAMPING_OPT_TX_SWHW: Request both hardware and software timestamps for outgoing packetsdrivers/net/ethernet/engleder/Kconfig +1
-0@@ -22,6 +22,7 @@ config TSNEP depends on PTP_1588_CLOCK_OPTIONAL select PHYLIB select PAGE_POOL + select SKB_MARK_NAPI_ID help Support for the Engleder TSN endpoint Ethernet MAC IP Core.drivers/net/ethernet/intel/Kconfig +1
-0@@ -376,6 +376,7 @@ config IGC depends on PCI depends on PTP_1588_CLOCK_OPTIONAL depends on ETHTOOL_NETLINK + select SKB_MARK_NAPI_ID help This driver supports Intel(R) Ethernet Controller I225-LM/I225-V family of adapters.include/linux/skbuff.h +2
-2@@ -1059,7 +1059,7 @@ struct sk_buff {__u16 vlan_tci; }; }; -#if defined(CONFIG_NET_RX_BUSY_POLL) || defined(CONFIG_XPS) +#if defined(CONFIG_SKB_MARK_NAPI_ID) || defined(CONFIG_XPS) union { unsigned int napi_id; unsigned int sender_cpu;@@ -1267,7 +1267,7 @@ static inline bool skb_pkt_type_ok(u32 ptype)*/ static inline unsigned int skb_napi_id (const struct sk_buff *skb) { -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID return skb->napi_id;#else return 0 ;include/net/busy_poll.h +1
-1@@ -130,7 +130,7 @@ static inline void sk_busy_loop(struct sock *sk, int nonblock)static inline void __skb_mark_napi_id (struct sk_buff *skb,const struct gro_node *gro) { -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID /* If the skb was already marked with a valid NAPI ID, avoid overwriting * it. */ include/trace/events/net.h +1
-1@@ -208,7 +208,7 @@ DECLARE_EVENT_CLASS(net_dev_rx_verbose_template,TP_fast_assign ( __assign_str(name); -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID __entry->napi_id =napi_id_valid (skb->napi_id) ? skb->napi_id :0 ;#else net/Kconfig +4
-0@@ -346,9 +346,13 @@ config CGROUP_NET_CLASSID Cgroup subsystem for use as general purpose socket classid marker that is being used in cls_cgroup and for netfilter matching. +config SKB_MARK_NAPI_ID + bool + config NET_RX_BUSY_POLL bool default y if !PREEMPT_RT || (PREEMPT_RT && !NETCONSOLE) + select SKB_MARK_NAPI_ID config BQL boolnet/core/filter.c +1
-1@@ -10274,7 +10274,7 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type,break ;case offsetof(struct __sk_buff , napi_id): -#if defined(CONFIG_NET_RX_BUSY_POLL ) +#if defined(CONFIG_SKB_MARK_NAPI_ID ) *insn++ =BPF_LDX_MEM (BPF_W , si->dst_reg, si->src_reg, bpf_target_off(struct sk_buff, napi_id, 4, target_size));net/core/skbuff.c +1
-1@@ -1581,7 +1581,7 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)#ifdef CONFIG_NETWORK_SECMARK CHECK_SKB_FIELD (secmark);#endif -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID CHECK_SKB_FIELD (napi_id);#endif #ifdef CONFIG_XPS Quoted 5 lines
base-commit:
d135ab453a7400a34930bdda1ef4bdc8acfac80e--
2.47.3Are you sure this does not make the preexisting timestamp lifetime issue more pathological? I think it needs to be fixed now as well. It was the last item mentioned by Sashiko in your review if I remember correctly.
Quoted 1 line
Paul
#!/usr/bin/env python3
# igc deferred RX timestamp: freed-page deref attempt on 4 KiB pages. # - queue small timestamped reply P0 (copied path, netdev_data ptr into page PG) # - stream large replies (frag path) so PG's two halves are handed to two # frag skbs; the second one makes igc_can_reuse_rx_page() fail and # __page_frag_cache_drain() drop the driver's references # - consume the large skbs: last page ref drops -> page freed # - recv P0 -> igc_get_tstamp() reads PG import ctypes, socket, struct, sys, time from pathlib import Path
IFACE = sys.argv[1] if len(sys.argv) > 1 else "enp2s0" N = int(sys.argv[2]) if len(sys.argv) > 2 else 560 PEER_MAC = "c0:74:2b:fe:5d:aa"SRC_IP, DST_IP = "198.18.0.2", "198.18.0.1" SMALL = 0
LARGE = 1400SO_ATTACH_FILTER = 26
class SockFilter(ctypes.Structure):
_fields_ = [("code", ctypes.c_ushort), ("jt", ctypes.c_ubyte),
("jf", ctypes.c_ubyte), ("k", ctypes.c_uint)]class SockFprog(ctypes.Structure):
_fields_ = [("len", ctypes.c_ushort),
("filter", ctypes.POINTER(SockFilter))]def bpf_prog(insns):
arr = (SockFilter * len(insns))(*insns)
return SockFprog(len(insns), ctypes.cast(arr, ctypes.POINTER(SockFilter))), arr
def attach_len_filter(sock, keep_large):
BPF_LD_W_LEN, BPF_JMP_JGT_K, BPF_RET_K = 0x80, 0x25, 0x06
if keep_large:
insns = [SockFilter(BPF_LD_W_LEN, 0, 0, 0),
SockFilter(BPF_JMP_JGT_K, 1, 0, 200),
SockFilter(BPF_RET_K, 0, 0, 0),
SockFilter(BPF_RET_K, 0, 0, 0x40000)]
else:
insns = [SockFilter(BPF_LD_W_LEN, 0, 0, 0),
SockFilter(BPF_JMP_JGT_K, 0, 1, 200),
SockFilter(BPF_RET_K, 0, 0, 0),
SockFilter(BPF_RET_K, 0, 0, 0x40000)]
prog, arr = bpf_prog(insns)
sock.setsockopt(socket.SOL_SOCKET, SO_ATTACH_FILTER,
ctypes.string_at(ctypes.byref(prog), ctypes.sizeof(prog)))
return arrdef csum(data):
if len(data) & 1:
data += b"\0"
total = sum(struct.unpack("!" + "H" * (len(data) // 2), data))
while total >> 16:
total = (total & 65535) + (total >> 16)
return (~total) & 65535def frame(seq, size):
src = bytes.fromhex(Path("/sys/class/net/" + IFACE + "/address")
.read_text().strip().replace(":", ""))
dst = bytes.fromhex(PEER_MAC.replace(":", ""))
payload = bytes(((i * 131 + seq * 17) & 255) for i in range(size))
icmp = struct.pack("!BBHHH", 8, 0, 0, 0x49C6, seq) + payload
icmp = icmp[:2] + struct.pack("!H", csum(icmp)) + icmp[4:]
ip = struct.pack("!BBHHHBBH4s4s", 0x45, 0, 20 + len(icmp), seq, 0x4000,
64, 1, 0, socket.inet_aton(SRC_IP), socket.inet_aton(DST_IP))
ip = ip[:10] + struct.pack("!H", csum(ip)) + ip[12:]
return dst + src + b"\x08\x00" + ip + icmpdef mksock(keep_large):
s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(3))
s.bind((IFACE, 0))
s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 64 << 20)
s.setsockopt(263, 23, 1)
s.setsockopt(socket.SOL_SOCKET, 37, 16 | 64)
attach_len_filter(s, keep_large)
s.setblocking(False)
return sseen = ctypes.create_string_buffer
small = mksock(False)
large = mksock(True)
# reset stats small.getsockopt(263, 6, 8) large.getsockopt(263, 6, 8)
small.send(frame(900, SMALL))time.sleep(0.3)print("P0 queued on small socket", flush=True)
t0 = time.time()
for i in range(N):
large.send(frame(2000 + i, LARGE))
time.sleep(0.001)time.sleep(1.0)
pkt, drop = struct.unpack("=2I", large.getsockopt(263, 6, 8)) print("large burst sent %d, received %d, drops %d, %.3fs"
% (N, pkt, drop, time.time() - t0), flush=True)
# consume the large skbs; frees any page the driver had drained
got = 0
while True:
try:
large.recvmsg(4096, 256)
got += 1
if got % 128 == 0:
time.sleep(0)
except BlockingIOError:
break
print("drained %d large skbs" % got, flush=True)# now read P0: igc_get_tstamp() dereferences its stale netdev_data
try:
data, anc, flags, addr = small.recvmsg(2048, 512)
print("read P0: %d bytes" % len(data), flush=True)
except BlockingIOError:
print("P0 not queued!", flush=True)Quoted 212 lines · Paul Moses
Quoted 195 lines · Ding Meng
Commit
97dc7cd92ac6("ptp: Support late timestamp determination") added support for deferring RX timestamp conversion tondo_get_tstamp(). When the timestamp is consumed,get_timestamp()uses the skb's NAPI ID to find the device that owns the timestamp cookie and invoke its callback.Commit
e68b6e50fa35("udp: enable busy polling for all sockets") gated NAPI ID bookkeeping withCONFIG_NET_RX_BUSY_POLL. As a result, when busy polling is disabled, the skb may not carry a usable NAPI ID. The device lookup then fails, so the driver callback is not invoked.get_timestamp()falls back to hwtstamp, which does not contain the converted timestamp, resulting in an incorrect RX hardware timestamp.Record skb NAPI IDs independently of busy-poll support to support drivers that use deferred timestamp conversion and future driver features that need to look up a device by its NAPI ID.
Signed-off-by Ding Meng <[email protected]>Reviewed-by Florian Bezdeka <[email protected]>---
In the discussion of the issue reported at
https://lore.kernel.org/netdev/[email protected]/
this previous patch added an igc-specific fallback for configurations withCONFIG_NET_RX_BUSY_POLLdisabled. It populated skb's hwtstamp field with a timestamp converted using the default hardware timer, allowingget_timestamp()to return it without invokingndo_get_tstamp(). But Jakub Kicinski noted that the proposed fix appeared to be a driver-specific workaround for a generic problem. The engleder driver would also be affected by the same issue.This patch introduces a new configuration option to enable NAPI ID bookkeeping independently of busy polling. The option is enabled whenever busy polling is enabled, preserving the existing behavior. It is also selected by the igc and engleder drivers, ensuring that skbs carry a NAPI ID even when busy polling is disabled.
Another approach considered was to require drivers using deferred timestamp conversion, such as igc and engleder, to enable busy polling. However, this would introduce an unnecessary dependency between two independent features: hardware timestamp reporting should not require busy polling to be enabled.
Timestamping has been tested only with igc; it has not been tested with engleder.
Documentation/networking/timestamping.rst | 11 ++++++++--- drivers/net/ethernet/engleder/Kconfig | 1 + drivers/net/ethernet/intel/Kconfig | 1 + include/linux/skbuff.h | 4 ++-- include/net/busy_poll.h | 2 +- include/trace/events/net.h | 2 +- net/Kconfig | 4 ++++ net/core/filter.c | 2 +- net/core/skbuff.c | 2 +- 9 files changed, 20 insertions(+), 9 deletions(-)Documentation/networking/timestamping.rst +8
-3@@ -278,9 +278,14 @@ SOF_TIMESTAMPING_OPT_PKTINFO: packets with hardware timestamps. The message contains struct scm_ts_pktinfo, which supplies the index of the real interface which received the packet and its length at layer 2. A valid (non-zero) - interface index will be returned only if CONFIG_NET_RX_BUSY_POLL is - enabled and the driver is using NAPI. The struct contains also two - other fields, but they are reserved and undefined. + interface index will be returned only if CONFIG_SKB_MARK_NAPI_ID is + enabled and the driver is using NAPI. This hidden configuration is + selected automatically by busy-poll support and by drivers that need + skb NAPI IDs to resolve deferred hardware timestamps. Drivers that + use deferred timestamp conversion must select it so the networking + stack can find the device and call its timestamp callback even when + busy polling is disabled. The struct contains also two other fields, + but they are reserved and undefined. SOF_TIMESTAMPING_OPT_TX_SWHW: Request both hardware and software timestamps for outgoing packetsdrivers/net/ethernet/engleder/Kconfig +1
-0@@ -22,6 +22,7 @@ config TSNEP depends on PTP_1588_CLOCK_OPTIONAL select PHYLIB select PAGE_POOL + select SKB_MARK_NAPI_ID help Support for the Engleder TSN endpoint Ethernet MAC IP Core.drivers/net/ethernet/intel/Kconfig +1
-0@@ -376,6 +376,7 @@ config IGC depends on PCI depends on PTP_1588_CLOCK_OPTIONAL depends on ETHTOOL_NETLINK + select SKB_MARK_NAPI_ID help This driver supports Intel(R) Ethernet Controller I225-LM/I225-V family of adapters.include/linux/skbuff.h +2
-2@@ -1059,7 +1059,7 @@ struct sk_buff {__u16 vlan_tci; }; }; -#if defined(CONFIG_NET_RX_BUSY_POLL) || defined(CONFIG_XPS) +#if defined(CONFIG_SKB_MARK_NAPI_ID) || defined(CONFIG_XPS) union { unsigned int napi_id; unsigned int sender_cpu;@@ -1267,7 +1267,7 @@ static inline bool skb_pkt_type_ok(u32 ptype)*/ static inline unsigned int skb_napi_id (const struct sk_buff *skb) { -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID return skb->napi_id;#else return 0 ;include/net/busy_poll.h +1
-1@@ -130,7 +130,7 @@ static inline void sk_busy_loop(struct sock *sk, int nonblock)static inline void __skb_mark_napi_id (struct sk_buff *skb,const struct gro_node *gro) { -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID /* If the skb was already marked with a valid NAPI ID, avoid overwriting * it. */ include/trace/events/net.h +1
-1@@ -208,7 +208,7 @@ DECLARE_EVENT_CLASS(net_dev_rx_verbose_template,TP_fast_assign ( __assign_str(name); -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID __entry->napi_id =napi_id_valid (skb->napi_id) ? skb->napi_id :0 ;#else net/Kconfig +4
-0@@ -346,9 +346,13 @@ config CGROUP_NET_CLASSID Cgroup subsystem for use as general purpose socket classid marker that is being used in cls_cgroup and for netfilter matching. +config SKB_MARK_NAPI_ID + bool + config NET_RX_BUSY_POLL bool default y if !PREEMPT_RT || (PREEMPT_RT && !NETCONSOLE) + select SKB_MARK_NAPI_ID config BQL boolnet/core/filter.c +1
-1@@ -10274,7 +10274,7 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type,break ;case offsetof(struct __sk_buff , napi_id): -#if defined(CONFIG_NET_RX_BUSY_POLL ) +#if defined(CONFIG_SKB_MARK_NAPI_ID ) *insn++ =BPF_LDX_MEM (BPF_W , si->dst_reg, si->src_reg, bpf_target_off(struct sk_buff, napi_id, 4, target_size));net/core/skbuff.c +1
-1@@ -1581,7 +1581,7 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)#ifdef CONFIG_NETWORK_SECMARK CHECK_SKB_FIELD (secmark);#endif -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID CHECK_SKB_FIELD (napi_id);#endif #ifdef CONFIG_XPS Quoted 5 lines
base-commit:
d135ab453a7400a34930bdda1ef4bdc8acfac80e--
2.47.3Are you sure this does not make the preexisting timestamp lifetime issue more pathological? I think it needs to be fixed now as well. It was the last item mentioned by Sashiko in your review if I remember correctly.
Quoted 1 line
Paul
The hardware timestamp lifetime issue may indeed exist, but it is independent of this patch. Even if that issus is fixed, we still need to obtain the netdevice from the skb, so the decoupling configuration introduced by this patch is still necessary.
Ding Meng
Quoted 213 lines · Ding Meng
Quoted 212 lines · Paul Moses
Quoted 195 lines · Ding Meng
Commit
97dc7cd92ac6("ptp: Support late timestamp determination") added support for deferring RX timestamp conversion tondo_get_tstamp(). When the timestamp is consumed,get_timestamp()uses the skb's NAPI ID to find the device that owns the timestamp cookie and invoke its callback.Commit
e68b6e50fa35("udp: enable busy polling for all sockets") gated NAPI ID bookkeeping withCONFIG_NET_RX_BUSY_POLL. As a result, when busy polling is disabled, the skb may not carry a usable NAPI ID. The device lookup then fails, so the driver callback is not invoked.get_timestamp()falls back to hwtstamp, which does not contain the converted timestamp, resulting in an incorrect RX hardware timestamp.Record skb NAPI IDs independently of busy-poll support to support drivers that use deferred timestamp conversion and future driver features that need to look up a device by its NAPI ID.
Signed-off-by Ding Meng <[email protected]>Reviewed-by Florian Bezdeka <[email protected]>---
In the discussion of the issue reported at
https://lore.kernel.org/netdev/[email protected]/
this previous patch added an igc-specific fallback for configurations withCONFIG_NET_RX_BUSY_POLLdisabled. It populated skb's hwtstamp field with a timestamp converted using the default hardware timer, allowingget_timestamp()to return it without invokingndo_get_tstamp(). But Jakub Kicinski noted that the proposed fix appeared to be a driver-specific workaround for a generic problem. The engleder driver would also be affected by the same issue.This patch introduces a new configuration option to enable NAPI ID bookkeeping independently of busy polling. The option is enabled whenever busy polling is enabled, preserving the existing behavior. It is also selected by the igc and engleder drivers, ensuring that skbs carry a NAPI ID even when busy polling is disabled.
Another approach considered was to require drivers using deferred timestamp conversion, such as igc and engleder, to enable busy polling. However, this would introduce an unnecessary dependency between two independent features: hardware timestamp reporting should not require busy polling to be enabled.
Timestamping has been tested only with igc; it has not been tested with engleder.
Documentation/networking/timestamping.rst | 11 ++++++++--- drivers/net/ethernet/engleder/Kconfig | 1 + drivers/net/ethernet/intel/Kconfig | 1 + include/linux/skbuff.h | 4 ++-- include/net/busy_poll.h | 2 +- include/trace/events/net.h | 2 +- net/Kconfig | 4 ++++ net/core/filter.c | 2 +- net/core/skbuff.c | 2 +- 9 files changed, 20 insertions(+), 9 deletions(-)Documentation/networking/timestamping.rst +8
-3@@ -278,9 +278,14 @@ SOF_TIMESTAMPING_OPT_PKTINFO: packets with hardware timestamps. The message contains struct scm_ts_pktinfo, which supplies the index of the real interface which received the packet and its length at layer 2. A valid (non-zero) - interface index will be returned only if CONFIG_NET_RX_BUSY_POLL is - enabled and the driver is using NAPI. The struct contains also two - other fields, but they are reserved and undefined. + interface index will be returned only if CONFIG_SKB_MARK_NAPI_ID is + enabled and the driver is using NAPI. This hidden configuration is + selected automatically by busy-poll support and by drivers that need + skb NAPI IDs to resolve deferred hardware timestamps. Drivers that + use deferred timestamp conversion must select it so the networking + stack can find the device and call its timestamp callback even when + busy polling is disabled. The struct contains also two other fields, + but they are reserved and undefined. SOF_TIMESTAMPING_OPT_TX_SWHW: Request both hardware and software timestamps for outgoing packetsdrivers/net/ethernet/engleder/Kconfig +1
-0@@ -22,6 +22,7 @@ config TSNEP depends on PTP_1588_CLOCK_OPTIONAL select PHYLIB select PAGE_POOL + select SKB_MARK_NAPI_ID help Support for the Engleder TSN endpoint Ethernet MAC IP Core.drivers/net/ethernet/intel/Kconfig +1
-0@@ -376,6 +376,7 @@ config IGC depends on PCI depends on PTP_1588_CLOCK_OPTIONAL depends on ETHTOOL_NETLINK + select SKB_MARK_NAPI_ID help This driver supports Intel(R) Ethernet Controller I225-LM/I225-V family of adapters.include/linux/skbuff.h +2
-2@@ -1059,7 +1059,7 @@ struct sk_buff {__u16 vlan_tci; }; }; -#if defined(CONFIG_NET_RX_BUSY_POLL) || defined(CONFIG_XPS) +#if defined(CONFIG_SKB_MARK_NAPI_ID) || defined(CONFIG_XPS) union { unsigned int napi_id; unsigned int sender_cpu;@@ -1267,7 +1267,7 @@ static inline bool skb_pkt_type_ok(u32 ptype)*/ static inline unsigned int skb_napi_id (const struct sk_buff *skb) { -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID return skb->napi_id;#else return 0 ;include/net/busy_poll.h +1
-1@@ -130,7 +130,7 @@ static inline void sk_busy_loop(struct sock *sk, int nonblock)static inline void __skb_mark_napi_id (struct sk_buff *skb,const struct gro_node *gro) { -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID /* If the skb was already marked with a valid NAPI ID, avoid overwriting * it. */ include/trace/events/net.h +1
-1@@ -208,7 +208,7 @@ DECLARE_EVENT_CLASS(net_dev_rx_verbose_template,TP_fast_assign ( __assign_str(name); -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID __entry->napi_id =napi_id_valid (skb->napi_id) ? skb->napi_id :0 ;#else net/Kconfig +4
-0@@ -346,9 +346,13 @@ config CGROUP_NET_CLASSID Cgroup subsystem for use as general purpose socket classid marker that is being used in cls_cgroup and for netfilter matching. +config SKB_MARK_NAPI_ID + bool + config NET_RX_BUSY_POLL bool default y if !PREEMPT_RT || (PREEMPT_RT && !NETCONSOLE) + select SKB_MARK_NAPI_ID config BQL boolnet/core/filter.c +1
-1@@ -10274,7 +10274,7 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type,break ;case offsetof(struct __sk_buff , napi_id): -#if defined(CONFIG_NET_RX_BUSY_POLL ) +#if defined(CONFIG_SKB_MARK_NAPI_ID ) *insn++ =BPF_LDX_MEM (BPF_W , si->dst_reg, si->src_reg, bpf_target_off(struct sk_buff, napi_id, 4, target_size));net/core/skbuff.c +1
-1@@ -1581,7 +1581,7 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)#ifdef CONFIG_NETWORK_SECMARK CHECK_SKB_FIELD (secmark);#endif -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID CHECK_SKB_FIELD (napi_id);#endif #ifdef CONFIG_XPS Quoted 5 lines
base-commit:
d135ab453a7400a34930bdda1ef4bdc8acfac80e--
2.47.3Are you sure this does not make the preexisting timestamp lifetime issue more pathological? I think it needs to be fixed now as well. It was the last item mentioned by Sashiko in your review if I remember correctly.
Quoted 9 lines
Quoted 1 line
Paul
The hardware timestamp lifetime issue may indeed exist, but it is independent of this patch. Even if that issus is fixed, we still need to obtain the netdevice from the skb, so the decoupling configuration introduced by this patch is still necessary.
Ding Meng
Your patch changes non busy poll kernels from returning the raw cookie pointer to dereferencing that cookie just like busy poll already did.
So I guess that's an improvement? My apathy has reached a threshold where that sounds good to me.
The big question is why does igc alone need core modification to properly store Timer 1. Seemed like an intel question so I digress.
Good luck and have fun
[ 7.971832] ================================================================== [ 7.971852] BUG: KASAN: use-after-free in igc_ptp_rx_pktstamp+0x12c/0x190 [ 7.972002] Read of size 4 at addr ffff88800549c008 by task test/197 [ 7.972013] [ 7.972041] CPU: 0 UID: 65534 PID: 197 Comm: test Not tainted 7.3.0-nobusy-patched-20261105+ #1 PREEMPT_RT [ 7.972064] Call Trace: [ 7.972103] <TASK> [ 7.972122] dump_stack_lvl+0x43/0x60 [ 7.972215] print_address_description+0x55/0x1d0 [ 7.972265] ? igc_ptp_rx_pktstamp+0x12c/0x190 [ 7.972285] print_report+0x58/0x70 [ 7.972295] kasan_report+0x130/0x170 [ 7.972356] ? igc_ptp_rx_pktstamp+0x12c/0x190 [ 7.972366] igc_ptp_rx_pktstamp+0x12c/0x190 [ 7.972375] __sock_recv_timestamp+0x72b/0xe10 [ 7.972451] __sock_recv_cmsgs+0x168/0x3c0 [ 7.972461] udp_recvmsg+0x4c9/0xb40 [ 7.972525] ? __pfx_inet_recvmsg+0x10/0x10 [ 7.972546] sock_recvmsg+0x125/0x170 [ 7.972556] ____sys_recvmsg+0x167/0x3b0 [ 7.972567] __sys_recvmsg+0x14c/0x1b0 [ 7.972578] ? do_syscall_64+0x115/0x310 [ 7.972660] do_syscall_64+0xdb/0x310 [ 7.972671] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 7.972697] RIP: 0033:0x20af4c [ 7.972726] Code: be 01 00 00 00 0f 05 c3 cc cc cc cc cc cc 4d 89 cb 48 89 f8 4c 8b 4c 24 08 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 d8 0f 05 <c3> cc cc cc e9 db ff ff ff cc cc cc c3 cc cc cc cc cc cc cc 55 41 [ 7.972744] RSP: 002b:00007ffd6dcb7308 EFLAGS: 00000246 ORIG_RAX: 000000000000002f [ 7.972775] RAX: ffffffffffffffda RBX: 00007ffd6dcb73a0 RCX: 000000000020af4c [ 7.972783] RDX: 0000000000000000 RSI: 00007ffd6dcb7320 RDI: 0000000000000003 [ 7.972790] RBP: 0000000000000003 R08: 0000000000000000 R09: 0000000000000000 [ 7.972796] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000230 [ 7.972802] R13: 00007ffd6dcb73e0 R14: 0000000000000000 R15: 00007ffd6dcb75e0 [ 7.972812] </TASK>
Quoted 195 lines · Ding Meng
Commit
97dc7cd92ac6("ptp: Support late timestamp determination") added support for deferring RX timestamp conversion tondo_get_tstamp(). When the timestamp is consumed,get_timestamp()uses the skb's NAPI ID to find the device that owns the timestamp cookie and invoke its callback.Commit
e68b6e50fa35("udp: enable busy polling for all sockets") gated NAPI ID bookkeeping withCONFIG_NET_RX_BUSY_POLL. As a result, when busy polling is disabled, the skb may not carry a usable NAPI ID. The device lookup then fails, so the driver callback is not invoked.get_timestamp()falls back to hwtstamp, which does not contain the converted timestamp, resulting in an incorrect RX hardware timestamp.Record skb NAPI IDs independently of busy-poll support to support drivers that use deferred timestamp conversion and future driver features that need to look up a device by its NAPI ID.
Signed-off-by Ding Meng <[email protected]>Reviewed-by Florian Bezdeka <[email protected]>---
In the discussion of the issue reported at
https://lore.kernel.org/netdev/[email protected]/
this previous patch added an igc-specific fallback for configurations withCONFIG_NET_RX_BUSY_POLLdisabled. It populated skb's hwtstamp field with a timestamp converted using the default hardware timer, allowingget_timestamp()to return it without invokingndo_get_tstamp(). But Jakub Kicinski noted that the proposed fix appeared to be a driver-specific workaround for a generic problem. The engleder driver would also be affected by the same issue.This patch introduces a new configuration option to enable NAPI ID bookkeeping independently of busy polling. The option is enabled whenever busy polling is enabled, preserving the existing behavior. It is also selected by the igc and engleder drivers, ensuring that skbs carry a NAPI ID even when busy polling is disabled.
Another approach considered was to require drivers using deferred timestamp conversion, such as igc and engleder, to enable busy polling. However, this would introduce an unnecessary dependency between two independent features: hardware timestamp reporting should not require busy polling to be enabled.
Timestamping has been tested only with igc; it has not been tested with engleder.
Documentation/networking/timestamping.rst | 11 ++++++++--- drivers/net/ethernet/engleder/Kconfig | 1 + drivers/net/ethernet/intel/Kconfig | 1 + include/linux/skbuff.h | 4 ++-- include/net/busy_poll.h | 2 +- include/trace/events/net.h | 2 +- net/Kconfig | 4 ++++ net/core/filter.c | 2 +- net/core/skbuff.c | 2 +- 9 files changed, 20 insertions(+), 9 deletions(-)Documentation/networking/timestamping.rst +8
-3@@ -278,9 +278,14 @@ SOF_TIMESTAMPING_OPT_PKTINFO: packets with hardware timestamps. The message contains struct scm_ts_pktinfo, which supplies the index of the real interface which received the packet and its length at layer 2. A valid (non-zero) - interface index will be returned only if CONFIG_NET_RX_BUSY_POLL is - enabled and the driver is using NAPI. The struct contains also two - other fields, but they are reserved and undefined. + interface index will be returned only if CONFIG_SKB_MARK_NAPI_ID is + enabled and the driver is using NAPI. This hidden configuration is + selected automatically by busy-poll support and by drivers that need + skb NAPI IDs to resolve deferred hardware timestamps. Drivers that + use deferred timestamp conversion must select it so the networking + stack can find the device and call its timestamp callback even when + busy polling is disabled. The struct contains also two other fields, + but they are reserved and undefined. SOF_TIMESTAMPING_OPT_TX_SWHW: Request both hardware and software timestamps for outgoing packetsdrivers/net/ethernet/engleder/Kconfig +1
-0@@ -22,6 +22,7 @@ config TSNEP depends on PTP_1588_CLOCK_OPTIONAL select PHYLIB select PAGE_POOL + select SKB_MARK_NAPI_ID help Support for the Engleder TSN endpoint Ethernet MAC IP Core.drivers/net/ethernet/intel/Kconfig +1
-0@@ -376,6 +376,7 @@ config IGC depends on PCI depends on PTP_1588_CLOCK_OPTIONAL depends on ETHTOOL_NETLINK + select SKB_MARK_NAPI_ID help This driver supports Intel(R) Ethernet Controller I225-LM/I225-V family of adapters.include/linux/skbuff.h +2
-2@@ -1059,7 +1059,7 @@ struct sk_buff {__u16 vlan_tci; }; }; -#if defined(CONFIG_NET_RX_BUSY_POLL) || defined(CONFIG_XPS) +#if defined(CONFIG_SKB_MARK_NAPI_ID) || defined(CONFIG_XPS) union { unsigned int napi_id; unsigned int sender_cpu;@@ -1267,7 +1267,7 @@ static inline bool skb_pkt_type_ok(u32 ptype)*/ static inline unsigned int skb_napi_id (const struct sk_buff *skb) { -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID return skb->napi_id;#else return 0 ;include/net/busy_poll.h +1
-1@@ -130,7 +130,7 @@ static inline void sk_busy_loop(struct sock *sk, int nonblock)static inline void __skb_mark_napi_id (struct sk_buff *skb,const struct gro_node *gro) { -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID /* If the skb was already marked with a valid NAPI ID, avoid overwriting * it. */ include/trace/events/net.h +1
-1@@ -208,7 +208,7 @@ DECLARE_EVENT_CLASS(net_dev_rx_verbose_template,TP_fast_assign ( __assign_str(name); -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID __entry->napi_id =napi_id_valid (skb->napi_id) ? skb->napi_id :0 ;#else net/Kconfig +4
-0@@ -346,9 +346,13 @@ config CGROUP_NET_CLASSID Cgroup subsystem for use as general purpose socket classid marker that is being used in cls_cgroup and for netfilter matching. +config SKB_MARK_NAPI_ID + bool + config NET_RX_BUSY_POLL bool default y if !PREEMPT_RT || (PREEMPT_RT && !NETCONSOLE) + select SKB_MARK_NAPI_ID config BQL boolnet/core/filter.c +1
-1@@ -10274,7 +10274,7 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type,break ;case offsetof(struct __sk_buff , napi_id): -#if defined(CONFIG_NET_RX_BUSY_POLL ) +#if defined(CONFIG_SKB_MARK_NAPI_ID ) *insn++ =BPF_LDX_MEM (BPF_W , si->dst_reg, si->src_reg, bpf_target_off(struct sk_buff, napi_id, 4, target_size));net/core/skbuff.c +1
-1@@ -1581,7 +1581,7 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)#ifdef CONFIG_NETWORK_SECMARK CHECK_SKB_FIELD (secmark);#endif -#ifdef CONFIG_NET_RX_BUSY_POLL +#ifdef CONFIG_SKB_MARK_NAPI_ID CHECK_SKB_FIELD (napi_id);#endif #ifdef CONFIG_XPS
Quoted 1 line
base-commit:
d135ab453a7400a34930bdda1ef4bdc8acfac80e
Jakub Kicinski
maintainerDocumentation/networking/timestamping.rst SOF_TIMESTAMPING_OPT_PKTINFO: · line 288
Quoted 8 lines · On Thu, 5 Nov 2026 15:16:08 +0800 Ding Meng wrote:
Documentation/networking/timestamping.rst +8
-0+ interface index will be returned only if CONFIG_SKB_MARK_NAPI_ID is + enabled and the driver is using NAPI. This hidden configuration is + selected automatically by busy-poll support and by drivers that need + skb NAPI IDs to resolve deferred hardware timestamps. Drivers that + use deferred timestamp conversion must select it so the networking + stack can find the device and call its timestamp callback even when + busy polling is disabled. The struct contains also two other fields, + but they are reserved and undefined.
Just take napi_id from under CONFIG_NET_RX_BUSY_POLL instead of complicating everyone's lives.
Signature · 1 line
pw-bot: cr
Quoted 10 lines · Jakub Kicinski
Documentation/networking/timestamping.rst SOF_TIMESTAMPING_OPT_PKTINFO: · line 288
Quoted 8 lines · On Thu, 5 Nov 2026 15:16:08 +0800 Ding Meng wrote:
Documentation/networking/timestamping.rst +8
-0+ interface index will be returned only if CONFIG_SKB_MARK_NAPI_ID is + enabled and the driver is using NAPI. This hidden configuration is + selected automatically by busy-poll support and by drivers that need + skb NAPI IDs to resolve deferred hardware timestamps. Drivers that + use deferred timestamp conversion must select it so the networking + stack can find the device and call its timestamp callback even when + busy polling is disabled. The struct contains also two other fields, + but they are reserved and undefined.
Quoted 4 lines
Just take
napi_idfrom underCONFIG_NET_RX_BUSY_POLLinstead of complicating everyone's lives.Signature · 1 line
pw-bot: cr
When BUSY_POLL is n under PREEMPT_RT && NETCONSOLE, igc fails to get RX hardware timestamps.
Then, drivers that use deferred timestamp conversion (e.g. igc, engleder) must specify a busy poll dependency if they want to obtain the original net device upon consuming the skb. However, this dependency is far from obvious, and annotating it for future features of this kind will be very hard to discover.
Configuring the skb napi ID separately
from busy poll seems cleaner and more reasonable.
Quoted 7 lines
Then, drivers that use deferred timestamp conversion (e.g. igc, engleder) must specify a busy poll dependency if they want to obtain the original net device upon consuming the skb. However, this dependency is far from obvious, and annotating it for future features of this kind will be very hard to discover.
The "deferred timestamp conversion" was incomplete is what I'm saying.
This started with 97dc7cd92ac6, 0abb62b68252 and 069b142f5819 were built upon it, so maybe Gerhard should decide the path forward?
Quoted 8 lines · Paul Moses
Quoted 7 lines
Then, drivers that use deferred timestamp conversion (e.g. igc, engleder) must specify a busy poll dependency if they want to obtain the original net device upon consuming the skb. However, this dependency is far from obvious, and annotating it for future features of this kind will be very hard to discover.
Quoted 4 lines
The "deferred timestamp conversion" was incomplete is what I'm saying.
This started with
97dc7cd92ac6,0abb62b68252and069b142f5819were built upon it, so maybe Gerhard should decide the path forward?
The deferred timestamp conversion is a niche feature for TSN to solve the working clock / global time problem in TSN networks. IMO there is no need to make it working as soon as igc or tsnep drivers are enabled. It would be ok to fall back to normal vclock behavior like all other drivers if CONFIG_NET_RX_BUSY_POLL=n. For me it is ok that NETCONSOLE is not possible for PREEMPT_RT in combination with this feature.
There are already so many things to consider to get TSN working. To not enable NETCONSOLE on PREEMPT_RT for deferred timestamp conversion would be just one of many.
@Ding Meng: Do you actually need the NETCONSOLE in this combination? On productive systems likely not these days due to CRA.
Gerhard
Quoted 21 lines · Gerhard Engleder
Quoted 8 lines · Paul Moses
Quoted 7 lines
Then, drivers that use deferred timestamp conversion (e.g. igc, engleder) must specify a busy poll dependency if they want to obtain the original net device upon consuming the skb. However, this dependency is far from obvious, and annotating it for future features of this kind will be very hard to discover.
Quoted 4 lines
The "deferred timestamp conversion" was incomplete is what I'm saying.
This started with
97dc7cd92ac6,0abb62b68252and069b142f5819were built upon it, so maybe Gerhard should decide the path forward?The deferred timestamp conversion is a niche feature for TSN to solve the working clock / global time problem in TSN networks. IMO there is no need to make it working as soon as igc or tsnep drivers are enabled. It would be ok to fall back to normal vclock behavior like all other drivers if
CONFIG_NET_RX_BUSY_POLL=n. For me it is ok that NETCONSOLE is not possible forPREEMPT_RTin combination with this feature.
Quoted 8 lines
There are already so many things to consider to get TSN working. To not enable NETCONSOLE on
PREEMPT_RTfor deferred timestamp conversion would be just one of many.@Ding Meng: Do you actually need the NETCONSOLE in this combination? On productive systems likely not these days due to CRA.
Gerhard
OK, understand. Thanks for your comments, Gerhard. Actuallly, we solved this issue by disabling netconsole and enabling busy poll. This is indeed a quite rare scenario, but when it happens, it is a bit difficult to figure out that this was the root cause.
Ding Meng
Jakub Kicinski
maintainerQuoted 19 lines · On Thu, 12 Nov 2026 12:33:57 +0800 Ding Meng wrote:
Quoted 10 lines · Jakub Kicinski
Documentation/networking/timestamping.rst SOF_TIMESTAMPING_OPT_PKTINFO: · line 288
Quoted 8 lines · On Thu, 5 Nov 2026 15:16:08 +0800 Ding Meng wrote:
Documentation/networking/timestamping.rst +8
-0+ interface index will be returned only if CONFIG_SKB_MARK_NAPI_ID is + enabled and the driver is using NAPI. This hidden configuration is + selected automatically by busy-poll support and by drivers that need + skb NAPI IDs to resolve deferred hardware timestamps. Drivers that + use deferred timestamp conversion must select it so the networking + stack can find the device and call its timestamp callback even when + busy polling is disabled. The struct contains also two other fields, + but they are reserved and undefined.Quoted 4 lines
Just take
napi_idfrom underCONFIG_NET_RX_BUSY_POLLinstead of complicating everyone's lives.Signature · 1 line
pw-bot: crWhen
BUSY_POLLis n underPREEMPT_RT&& NETCONSOLE, igc fails to get RX hardware timestamps.
Quoted 8 lines
Then, drivers that use deferred timestamp conversion (e.g. igc, engleder) must specify a busy poll dependency if they want to obtain the original net device upon consuming the skb. However, this dependency is far from obvious, and annotating it for future features of this kind will be very hard to discover.
Configuring the skb napi ID separately
from busy poll seems cleaner and more reasonable.
"take from under" == make it always compiled in