From: sashiko-bot@kernel.org
To: wei.fang@oss.nxp.com
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH v2 net-next 7/7] net: dsa: netc: add PTP one-step timestamping support
Date: Sun, 09 Aug 2026 03:19:06 +0000 [thread overview]
Message-ID: <20260809031906.C98761F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260808032146.2335723-9-wei.fang@oss.nxp.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Unloading the netc driver module does not wait for in-flight one-step Sync SKBs or asynchronous context destruction to complete, causing a kernel panic when unmapped module code is executed.
- [High] Forcefully clearing the `in_flight` flag during port disablement allows multiple one-step frames to be in flight concurrently, corrupting the shared SINGLE_STEP hardware register.
- [Medium] Manual software modification of the UDP checksum can evaluate to 0, which is invalid for IPv6 and disables checksums for IPv4.
--
--- Patch [7]: [PATCH v2 net-next 7/7] net: dsa: netc: add PTP one-step timestamping support ---
commit 4c7369406992245c62dd03f01878b8201447752c
Author: Wei Fang <wei.fang@nxp.com>
net: dsa: netc: add PTP one-step timestamping support
This commit adds PTP one-step TX timestamping support for the NETC switch.
It handles one-step Sync packets by deferring transmission to a process-context
work queue to accommodate sleeping hardware register accesses. It bypasses the
normal DSA user xmit path to avoid double counting TX stats.
> diff --git a/drivers/net/dsa/netc/netc_main.c b/drivers/net/dsa/netc/netc_main.c
> index 4e139ffc2f76a..55664045ba19d 100644
> --- a/drivers/net/dsa/netc/netc_main.c
> +++ b/drivers/net/dsa/netc/netc_main.c
[ ... ]
> @@ -1005,6 +1028,19 @@ static void netc_free_ports_resources(struct netc_switch *priv)
> continue;
>
> netc_port_purge_txtstamp_queue(np);
> +
> + /* dsa_tree_teardown() calls dsa_tree_teardown_ports() before
> + * dsa_tree_teardown_switches(), so netc_port_disable() is
> + * executed before netc_teardown() and purges onestep->queue,
> + * so here we only need to drop the port's owner reference.
> + * In-flight one-step skbs still hold references via the
> + * destructor; the context (and its work) is freed only after
> + * the conduit frees the last in-flight skb. By then np may
> + * be gone, but the work no longer dereferences np because
> + * onestep->active has been cleared.
> + */
> + netc_onestep_put(np->onestep);
> + np->onestep = NULL;
> }
> }
[Severity: High]
Does unloading the netc driver module wait for in-flight one-step Sync SKBs
to complete transmission by the conduit device?
Because the driver drops its reference here and allows the module unload to
complete, the kernel could attempt to execute netc_onestep_skb_destructor()
after the module memory has been unmapped when the conduit eventually frees
the SKB, leading to a panic.
[ ... ]
> @@ -1579,6 +1622,7 @@ static int netc_port_enable(struct dsa_switch *ds, int port,
> static void netc_port_disable(struct dsa_switch *ds, int port)
> {
> struct netc_port *np = NETC_PORT(ds, port);
> + struct netc_onestep *onestep = np->onestep;
>
> /* When .port_disable() is called, .port_enable() may not have been
> * called. In this case, both the prepare_count and enable_count of
> @@ -1588,6 +1632,13 @@ static void netc_port_disable(struct dsa_switch *ds, int port)
> if (!np->enable)
> return;
>
> + if (onestep) {
> + mutex_lock(&onestep->work_lock);
> + onestep->active = false;
> + netc_port_purge_onestep_queue(onestep, true);
> + mutex_unlock(&onestep->work_lock);
> + }
> +
> clk_disable_unprepare(np->ref_clk);
> np->enable = false;
> }
> diff --git a/drivers/net/dsa/netc/netc_ptp.c b/drivers/net/dsa/netc/netc_ptp.c
> index 1384a6f31d1c1..d0423b3c8c33a 100644
> --- a/drivers/net/dsa/netc/netc_ptp.c
> +++ b/drivers/net/dsa/netc/netc_ptp.c
[ ... ]
> +static void netc_port_program_onestep(struct netc_port *np,
> + struct netc_onestep *onestep,
> + struct sk_buff *skb,
> + u64 tstamp)
> +{
[ ... ]
> + old_sec_h = __get_unaligned_t(__be16, hdr + tstamp_offset);
> + old_sec_l = __get_unaligned_t(__be32, hdr + tstamp_offset + 2);
> + old_ns = __get_unaligned_t(__be32, hdr + tstamp_offset + 6);
> + inet_proto_csum_replace2(&uh->check, skb, old_sec_h,
> + new_sec_h, false);
> + inet_proto_csum_replace4(&uh->check, skb, old_sec_l,
> + new_sec_l, false);
> + inet_proto_csum_replace4(&uh->check, skb, old_ns,
> + new_ns, false);
> + csum_update = true;
> + }
[Severity: Medium]
Could this manual software modification of the UDP checksum evaluate to 0?
A UDP checksum of 0 is invalid for IPv6 and disables checksums for IPv4.
Does this require a check to convert a 0 result into CSUM_MANGLED_0 (0xFFFF)
to prevent non-compliant packets?
[ ... ]
> +void netc_port_purge_onestep_queue(struct netc_onestep *onestep,
> + bool clear_flight)
> +{
> + struct sk_buff_head free_list;
> +
> + __skb_queue_head_init(&free_list);
> +
> + spin_lock_bh(&onestep->queue_lock);
> + skb_queue_splice_init(&onestep->queue, &free_list);
> + if (clear_flight)
> + onestep->in_flight = false;
> + spin_unlock_bh(&onestep->queue_lock);
> +
> + __skb_queue_purge(&free_list);
> +}
[Severity: High]
Does forcefully clearing the in_flight flag here during port disablement
allow a new frame to be dequeued if the port is quickly brought back up?
If so, a new frame could be programmed into the shared SINGLE_STEP hardware
register while the previous frame is still physically in flight in the conduit.
Could this break the 1-to-1 serialization required by the hardware and lead to
corrupted timestamps?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260808032146.2335723-1-wei.fang@oss.nxp.com?part=7
next prev parent reply other threads:[~2026-08-09 3:19 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-08 3:21 [PATCH v2 net-next 0/7] net: dsa: netc: add PTP support for NETC switch wei.fang
2026-08-08 3:21 ` [PATCH] net: dsa: netc: add PTP one-step timestamping support wei.fang
2026-08-08 3:26 ` Wei Fang
2026-08-08 3:21 ` [PATCH v2 net-next 1/7] ptp: netc: use ioread64_lo_hi/iowrite64_lo_hi for 64-bit register access wei.fang
2026-08-09 3:19 ` sashiko-bot
2026-08-08 3:21 ` [PATCH v2 net-next 2/7] ptp: netc: remove unnecessary pcie_flr() call in probe wei.fang
2026-08-09 3:19 ` sashiko-bot
2026-08-08 3:21 ` [PATCH v2 net-next 3/7] ptp: netc: export netc_timer_get_current_time() for cross-driver use wei.fang
2026-08-09 3:19 ` sashiko-bot
2026-08-10 1:30 ` Wei Fang (OSS)
2026-08-08 3:21 ` [PATCH v2 net-next 4/7] net: dsa: netc: use entry ID instead of pointer to track host flood rule wei.fang
2026-08-08 3:21 ` [PATCH v2 net-next 5/7] net: dsa: netc: enable ingress port filtering lookup by default wei.fang
2026-08-09 3:19 ` sashiko-bot
2026-08-10 2:40 ` Wei Fang (OSS)
2026-08-08 3:21 ` [PATCH v2 net-next 6/7] net: dsa: netc: add PTP two-step timestamping support wei.fang
2026-08-09 3:19 ` sashiko-bot
2026-08-10 3:33 ` Wei Fang (OSS)
2026-08-08 3:21 ` [PATCH v2 net-next 7/7] net: dsa: netc: add PTP one-step " wei.fang
2026-08-09 3:19 ` sashiko-bot [this message]
2026-08-10 7:31 ` Wei Fang (OSS)
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=20260809031906.C98761F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=imx@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=wei.fang@oss.nxp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.