Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: willemdebruijn.kernel@gmail.com
Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
	edumazet@google.com, pabeni@redhat.com, horms@kernel.org,
	andrew+netdev@lunn.ch, willemb@google.com
Subject: Re: [PATCH net-next v9 4/7] idpf: support pacing offload
Date: Fri, 11 Sep 2026 17:13:17 +0000	[thread overview]
Message-ID: <178914679743.219967.4781990764758262872@kernel.org> (raw)
In-Reply-To: <20260910171131.2532487-5-willemdebruijn.kernel@gmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider:

Critical: 0 · High: 1 · Medium: 1 · Low: 2

- [High] idpf advertises a non-zero netdev->max_pacing_offload_horizon
  (and therefore programs absolute CLOCK_TAI departure times into the…
- [Medium] The EDT horizon advertised to the networking core is taken
  verbatim from firmware and only bounds-checked against U32_MAX, while…
- [Low] idpf_vport_set_pacing_offload() writes
  netdev->max_pacing_offload_horizon (idpf_lib.c:832) from the…
- [Low] In idpf_send_get_edt_caps_msg() the firmware-supplied granularity
  is a u64 (gran_ns = le64_to_cpu(caps.tstamp_granularity_ns)) but is…

--

idpf: support pacing offload

This adds EDT (earliest departure time) support to idpf: EDT capabilities
are negotiated over virtchnl, the negotiated horizon is published as
netdev->max_pacing_offload_horizon, and skb->tstamp is programmed into the
23-bit timestamp field of the flow scheduling Tx descriptor.

A few questions below on the capability gating and on the horizon
encoding.

> diff --git a/drivers/net/ethernet/intel/idpf/idpf_lib.c b/drivers/net/ethernet/intel/idpf/idpf_lib.c
> index 827c795afcb62..cd1b173e3b276 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_lib.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_lib.c
> @@ -817,6 +817,21 @@ static void idpf_attach_and_open(struct idpf_adapter *adapter)
>  	}
>  }
>  
> +static void idpf_vport_set_pacing_offload(struct idpf_vport *vport,
> +					  struct net_device *netdev)
> +{
> +	struct idpf_adapter *adapter = vport->adapter;
> +	u32 max_horizon = 0;
> +
> +	if (adapter->edt_caps.time_horizon_ns &&
> +	    idpf_is_queue_model_split(vport->dflt_qv_rsrc.txq_model) &&
> +	    !idpf_is_cap_ena(adapter, IDPF_OTHER_CAPS,
> +			     VIRTCHNL2_CAP_SPLITQ_QSCHED))
> +		max_horizon = adapter->edt_caps.time_horizon_ns;
> +

[Severity: High]
The commit message says:

    Negotiate the feature with the device using virtchnl. Support is
    conditional on
    ...
    - PTP to ensure the NIC clock is synced to CLOCK_TAI.

Where is that PTP condition implemented?  idpf_vport_set_pacing_offload()
gates only on adapter->edt_caps.time_horizon_ns, split txq model and flow
scheduling.  It does not consult VIRTCHNL2_CAP_PTP, adapter->ptp, or the
result of idpf_ptp_init().

In idpf_vc_core_init() the EDT negotiation is gated only on
VIRTCHNL2_CAP_EDT and runs before idpf_ptp_init(), whose failure is
deliberately non-fatal:

	err = idpf_ptp_init(adapter);
	if (err)
		pci_err(adapter->pdev, "PTP init failed, err=%pe\n",
			ERR_PTR(err));

So with a control plane that advertises EDT but not PTP, or when
idpf_ptp_get_caps()/clock creation fails, edt_caps.time_horizon_ns stays
non-zero and the horizon is still published.

With CONFIG_PTP_1588_CLOCK=n the stub in idpf_ptp.h returns success while
leaving adapter->ptp NULL:

	static inline int idpf_ptp_init(struct idpf_adapter *adapter)
	{
		return 0;
	}

In that build there is no PHC at all and no way for userspace to steer the
device clock, yet pacing offload remains advertised and
idpf_tx_splitq_set_txtime() keeps writing host CLOCK_TAI values into the
descriptor.  Should the helper also require a working PTP clock, or should
the commit message drop the PTP claim?

Related: the device clock is seeded from CLOCK_REALTIME in
idpf_ptp_init():

		ts = ktime_to_timespec64(ktime_get_real());
		err = idpf_ptp_settime64(&adapter->ptp->info, &ts);

while the new Tx path converts everything to CLOCK_TAI.  Is the epoch
assumed by the descriptor only correct after an external synchronizer has
corrected the PHC?

> +	WRITE_ONCE(netdev->max_pacing_offload_horizon, max_horizon);
> +}
> +

[Severity: Low]
Should this write be done under rtnl_lock()?  The RTNL side reads the same
field with a plain load in validate_linkmsg() before do_setlink() sets
dev->pacing_offload:

	net/core/rtnetlink.c:validate_linkmsg() {
		if (nla_get_u32(tb[IFLA_PACING_OFFLOAD]) &&
		    !dev->max_pacing_offload_horizon) {
	...
	}

idpf_cfg_netdev() is reached from idpf_init_task with no RTNL held, and on
the reset path it re-runs the helper on an already registered netdev, so an
"ip link set dev X pacing_offload on" validated against a non-zero horizon
can be followed immediately by the driver zeroing it.

That also leaves dev->pacing_offload set with
max_pacing_offload_horizon == 0, which is then dumped to userspace as
IFLA_PACING_OFFLOAD=1 together with IFLA_MAX_PACING_OFFLOAD_HORIZON=0.
Should the driver clear dev->pacing_offload when the horizon drops to 0?

>  /**
>   * idpf_cfg_netdev - Allocate, configure and register a netdev
>   * @vport: main vport structure
> @@ -850,6 +865,8 @@ static int idpf_cfg_netdev(struct idpf_vport *vport)
>  		np->max_tx_hdr_size = idpf_get_max_tx_hdr_size(adapter);
>  		vport->netdev = netdev;
>  
> +		idpf_vport_set_pacing_offload(vport, netdev);
> +
>  		return idpf_init_mac_addr(vport, netdev);
>  	}
>  

[ ... ]

> diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
> index 4311ffa30bb18..215a62161a049 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c

[ ... ]

> @@ -3011,6 +3017,63 @@ static bool idpf_tx_splitq_need_re(struct idpf_tx_queue *tx_q)
>  	return gap >= IDPF_TX_SPLITQ_RE_MIN_GAP;
>  }
>  
> +static void idpf_tx_splitq_set_txtime(const struct sk_buff *skb,
> +				      const struct idpf_tx_queue *tx_q,
> +				      struct idpf_tx_splitq_params *tx_params)
> +{

[ ... ]

> +	/* beyond offload horizon? set overflow bit only */
> +	if (ts > now + horizon) {
> +		tx_params->offload.desc_ts[2] =
> +			IDPF_TXD_FLOW_SCH_HORIZON_OVERFLOW_M;
> +		return;
> +	}
> +
> +	ts >>= tx_q->ts_gran_pow2;

[Severity: Medium]
Can the advertised horizon exceed what the descriptor can encode?  The
hardware field is 23 bits of granularity units:

	drivers/net/ethernet/intel/idpf/idpf_lan_txrx.h:
		/* [23:23] Horizon Overflow bit, [22:0] timestamp */
		u8 ts[3];

idpf_send_get_edt_caps_msg() checks time_horizon_ns only against U32_MAX
and never cross-checks it against (1 << 23) << ilog2(tstamp_granularity_ns).
For a control plane reporting tstamp_granularity_ns = 1 (passes both
checks) with time_horizon_ns = 1000000000, the encodable window is only
about 8.39 ms, but 1 s is published as netdev->max_pacing_offload_horizon
and accepted by sch_fq and SO_TXTIME.

Anything at or below the advertised horizon takes the non-overflow branch
here and gets truncated:

	tx_params->offload.desc_ts[2] = ((ts >> 16) & 0x7f);

so the departure time aliases back into the current window instead of being
flagged as overflow.  Would clamping help, e.g.
max_horizon = min(time_horizon_ns, (1ULL << 23) << tstamp_granularity_pow2)?

Separately, is the boundary test off by one even for self-consistent caps?
With horizon == (1 << 23) << gran, a timestamp exactly at now + horizon
passes the strict "ts > now + horizon" test, and after the shift it differs
from the scaled value of now by exactly 2^23, which masks to the same 23-bit
value, so the device would see "now" and release the packet a whole horizon
early.  Should the comparison be >= ?

> +
> +	/* 0 is valid 23b timestamp, but also means field unset.
> +	 * Increase by one to avoid this case
> +	 */
> +	if ((ts & 0x7fffff) == 0) {
> +		tx_params->offload.desc_ts[0] = 1;
> +		return;
> +	}
> +
> +	tx_params->offload.desc_ts[0] = ts & 0xff;
> +	tx_params->offload.desc_ts[1] = (ts >> 8) & 0xff;
> +	tx_params->offload.desc_ts[2] = ((ts >> 16) & 0x7f);
> +}
> +

[ ... ]

> diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> index 1caf527069737..928de868fa624 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c

[ ... ]

> @@ -573,6 +575,54 @@ static int idpf_send_get_caps_msg(struct idpf_adapter *adapter)
>  	return err;
>  }
>  

[ ... ]

> +	memcpy(&caps, xn_params.recv_mem.iov_base, sizeof(caps));
> +	horizon_ns = le64_to_cpu(caps.time_horizon_ns);
> +	gran_ns = le64_to_cpu(caps.tstamp_granularity_ns);
> +	if (horizon_ns > U32_MAX) {
> +		dev_warn(&adapter->pdev->dev, "EDT horizon exceeds U32\n");
> +		err = -EINVAL;
> +		goto free_rx_buf;
> +	}
> +	if (!gran_ns || !is_power_of_2(gran_ns)) {
> +		dev_warn(&adapter->pdev->dev, "Invalid EDT granularity\n");
> +		err = -EINVAL;
> +		goto free_rx_buf;
> +	}
> +
> +	adapter->edt_caps.time_horizon_ns = horizon_ns;
> +	adapter->edt_caps.tstamp_granularity_pow2 = ilog2(gran_ns);

[Severity: Low]
Does this validate a different value than the one it then uses?  gran_ns is
a u64, but is_power_of_2() takes unsigned long:

	include/linux/log2.h:
	static __always_inline __attribute__((const))
	bool is_power_of_2(unsigned long n)
	{
		return n - 1 < (n ^ (n - 1));
	}

IDPF has no "depends on 64BIT" in its Kconfig, so on 32-bit builds the
upper 32 bits are dropped for the check while ilog2(gran_ns) takes the
__ilog2_u64 path on the full value.  A response of 0x100000001 truncates to
1, passes the check, and yields tstamp_granularity_pow2 = 32, which is
copied into idpf_tx_queue.ts_gran_pow2 and used as the shift in
idpf_tx_splitq_set_txtime().  The same truncation rejects a legitimate
granularity of 2^32 on 32-bit.  Would testing the u64 directly, e.g.
gran_ns & (gran_ns - 1), plus an upper bound, be better here?

> +
> +free_rx_buf:
> +	libie_ctlq_release_rx_buf(&xn_params.recv_mem);
> +
> +	return err;
> +}
> +

[ ... ]

> @@ -3085,6 +3135,14 @@ int idpf_vc_core_init(struct idpf_adapter *adapter)
>  		}
>  	}
>  
> +	memset(&adapter->edt_caps, 0, sizeof(adapter->edt_caps));
> +	if (idpf_is_cap_ena(adapter, IDPF_OTHER_CAPS, VIRTCHNL2_CAP_EDT)) {
> +		err = idpf_send_get_edt_caps_msg(adapter);
> +		if (err)
> +			dev_err(&adapter->pdev->dev,
> +				"EDT init failed, err=%d\n", err);
> +	}
> +

[Severity: High]
This is the other half of the PTP question above: EDT caps are fetched here
gated only on VIRTCHNL2_CAP_EDT, and this runs before the idpf_ptp_init()
call further down whose error is only logged.  Should the EDT negotiation
either be gated on VIRTCHNL2_CAP_PTP, or moved after idpf_ptp_init() so the
caps can be zeroed when there is no usable PHC?

>  	pci_sriov_set_totalvfs(adapter->pdev, idpf_get_max_vfs(adapter));
>  	num_max_vports = idpf_get_max_vports(adapter);
>  	adapter->vports = kzalloc_objs(*adapter->vports, num_max_vports);

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260910171131.2532487-1-willemdebruijn.kernel%40gmail.com

  reply	other threads:[~2026-09-11 17:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10 17:10 [PATCH net-next v9 0/7] hardware pacing offload Willem de Bruijn
2026-09-10 17:10 ` [PATCH net-next v9 1/7] net: rtnetlink: add pacing_offload attribute to net_device Willem de Bruijn
2026-09-11 17:13   ` netdev-bot+sashiko
2026-09-12  0:25     ` Willem de Bruijn
2026-09-10 17:10 ` [PATCH net-next v9 2/7] net_sched: sch_fq: check device pacing offload Willem de Bruijn
2026-09-11 17:13   ` netdev-bot+sashiko
2026-09-12  0:33     ` Willem de Bruijn
2026-09-10 17:10 ` [PATCH net-next v9 3/7] net_sched: sch_fq: clear past skb->tstamp if offloading pacing Willem de Bruijn
2026-09-11 17:13   ` netdev-bot+sashiko
2026-09-12  0:36     ` Willem de Bruijn
2026-09-10 17:10 ` [PATCH net-next v9 4/7] idpf: support pacing offload Willem de Bruijn
2026-09-11 17:13   ` netdev-bot+sashiko [this message]
2026-09-12  0:46     ` Willem de Bruijn
2026-09-10 17:10 ` [PATCH net-next v9 5/7] selftests: drv-net: refactor so_txtime errqueue handling Willem de Bruijn
2026-09-10 17:10 ` [PATCH net-next v9 6/7] selftests: drv-net: in so_txtime tell apart sw from hw pacing Willem de Bruijn
2026-09-11 17:13   ` netdev-bot+sashiko
2026-09-12  0:47     ` Willem de Bruijn
2026-09-10 17:10 ` [PATCH net-next v9 7/7] selftests: drv-net: extend so_txtime with hw offload Willem de Bruijn
2026-09-11 17:13   ` netdev-bot+sashiko
2026-09-12  0:57     ` Willem de Bruijn

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=178914679743.219967.4781990764758262872@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    --cc=willemdebruijn.kernel@gmail.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