Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/2][pull request] i40e: add runtime-tunable ATR sample rate
@ 2026-12-04 21:38 Tony Nguyen
  2026-12-04 21:38 ` [PATCH net-next v2 1/2] i40e: move ATR sample rate from ring to PF level Tony Nguyen
  2026-12-04 21:38 ` [PATCH net-next v2 2/2] i40e: add devlink parameter for Flow Director ATR sample rate Tony Nguyen
  0 siblings, 2 replies; 5+ messages in thread
From: Tony Nguyen @ 2026-12-04 21:38 UTC (permalink / raw)
  To: davem, kuba, pabeni, edumazet, andrew+netdev, willemb, netdev
  Cc: Tony Nguyen, mheib, przemyslaw.kitszel, jiri, horms, corbet,
	skhan, rdunlap, linux-doc

Mohammad Heib says:

This series makes the Flow Director ATR sample rate configurable at
runtime through a devlink parameter.

On systems with many queues and high-rate TCP workloads, the fixed
default sampling interval can cause frequent Flow Director
reprogramming and TCP packet reordering. The optimal interval depends
on the workload and system configuration.

Patch 1 moves atr_sample_rate from per-ring to PF level, since it is
a global policy. It also triggers a PF reset when re-enabling ATR via
ethtool private flags so that fd_ena is reprogrammed in the TX queue
HW context.

Patch 2 exposes atr_sample_rate as a devlink runtime parameter so
administrators can tune it without rebuilding the driver.

Testing with iperf3 -t 60 showed ~7k TCP reordering events at the
default sample rate (20). Setting atr_sample_rate to 10000 reduced
reordering to ~769 (~90% reduction).
---
v2:
- Use '|=' instead of '=' when setting reset_needed for the ATR
  re-enable path, to avoid overwriting unrelated reset requests
- Folded the PF reset patch into patch 1 for bisect cleanliness
  (was patch 3/3)
- Skip PF reset when FD_SB (ntuple) already holds fd_ena high,
  avoiding unnecessary traffic disruption
- Fix LLDP EEXIST path to not drop unrelated reset requests
  (reset_needed &= ~REBUILD_FLAG instead of = 0)
- Flush existing ATR entries when setting atr_sample_rate to 0 via
  devlink, so stale filters do not persist on devices without HW
  ATR eviction
- Documentation: clarify that the sampling interval is per Tx queue
  and counts TCP packets only; fix formatting

v1: https://lore.kernel.org/netdev/20260917204541.3072415-1-anthony.l.nguyen@intel.com/

The following are changes since commit d5cf954cebe4f175dfd834e1dc471a3aa203ec7d:
  net: pktgen: hold if_lock across pktgen_find_dev() in __pktgen_NN_threads()
and are available in the git repository at:
  git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue 40GbE

Mohammad Heib (2):
  i40e: move ATR sample rate from ring to PF level
  i40e: add devlink parameter for Flow Director ATR sample rate

 Documentation/networking/devlink/i40e.rst     | 21 +++++++++
 drivers/net/ethernet/intel/i40e/i40e.h        |  1 +
 .../net/ethernet/intel/i40e/i40e_devlink.c    | 46 +++++++++++++++++++
 .../net/ethernet/intel/i40e/i40e_ethtool.c    | 12 ++++-
 drivers/net/ethernet/intel/i40e/i40e_main.c   |  9 ++--
 drivers/net/ethernet/intel/i40e/i40e_txrx.c   |  6 ++-
 drivers/net/ethernet/intel/i40e/i40e_txrx.h   |  3 +-
 7 files changed, 87 insertions(+), 11 deletions(-)

-- 
2.47.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net-next v2 1/2] i40e: move ATR sample rate from ring to PF level
  2026-12-04 21:38 [PATCH net-next v2 0/2][pull request] i40e: add runtime-tunable ATR sample rate Tony Nguyen
@ 2026-12-04 21:38 ` Tony Nguyen
  2026-12-05 22:29   ` netdev-bot+sashiko
  2026-12-04 21:38 ` [PATCH net-next v2 2/2] i40e: add devlink parameter for Flow Director ATR sample rate Tony Nguyen
  1 sibling, 1 reply; 5+ messages in thread
From: Tony Nguyen @ 2026-12-04 21:38 UTC (permalink / raw)
  To: davem, kuba, pabeni, edumazet, andrew+netdev, willemb, netdev
  Cc: Mohammad Heib, anthony.l.nguyen, przemyslaw.kitszel, jiri, horms,
	corbet, skhan, rdunlap, linux-doc

From: Mohammad Heib <mheib@redhat.com>

The ATR sample rate is currently stored per-ring and initialized when each
TX ring is configured. Since the sample rate is a global policy that
applies uniformly across all rings, it makes more sense to store it at
the PF level.

Move atr_sample_rate from struct i40e_ring to struct i40e_pf and initialize
it once during i40e_sw_init(). Update i40e_atr() to reference the PF-level
field. Change atr_count from u8 to u32 to match the sample rate type.

This also changes a user-visible behavior: previously, re-enabling ATR via
"ethtool --set-priv-flags ethX flow-director-atr on" did not resume
sampling until an ifdown/ifup or PF reset, because the per-ring sample
rate was latched at ring configuration time. With the PF-level rate always
initialized, the flag takes effect immediately.

Trigger a PF reset when re-enabling ATR so that fd_ena is re-evaluated
in the TX queue HW context.

Signed-off-by: Mohammad Heib <mheib@redhat.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
---
 drivers/net/ethernet/intel/i40e/i40e.h         |  1 +
 drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 12 +++++++++++-
 drivers/net/ethernet/intel/i40e/i40e_main.c    |  9 +++------
 drivers/net/ethernet/intel/i40e/i40e_txrx.c    |  6 ++++--
 drivers/net/ethernet/intel/i40e/i40e_txrx.h    |  3 +--
 5 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/intel/i40e/i40e.h b/drivers/net/ethernet/intel/i40e/i40e.h
index 1b6a8fbaa648..88eb40ee45f0 100644
--- a/drivers/net/ethernet/intel/i40e/i40e.h
+++ b/drivers/net/ethernet/intel/i40e/i40e.h
@@ -487,6 +487,7 @@ struct i40e_pf {
 	u16 rss_size_max;          /* HW defined max RSS queues */
 	u16 fdir_pf_filter_count;  /* num of guaranteed filters for this PF */
 	u16 num_alloc_vsi;         /* num VSIs this driver supports */
+	u32 atr_sample_rate;
 	bool wol_en;
 
 	struct hlist_head fdir_filter_list;
diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
index 58d842d67642..93dd9560af7e 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
@@ -5300,6 +5300,16 @@ static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
 	    test_bit(I40E_FLAG_SOURCE_PRUNING_DIS, changed_flags))
 		reset_needed = BIT(__I40E_PF_RESET_REQUESTED);
 
+	/* Re-enabling ATR requires a reset to reprogram fd_ena in the
+	 * TX queue HW context. Skip when FD_SB (ntuple) is already
+	 * enabled, since i40e_configure_tx_ring() sets fd_ena when
+	 * either FD flag is active.
+	 */
+	if (test_bit(I40E_FLAG_FD_ATR_ENA, changed_flags) &&
+	    test_bit(I40E_FLAG_FD_ATR_ENA, new_flags) &&
+	    !test_bit(I40E_FLAG_FD_SB_ENA, new_flags))
+		reset_needed |= BIT(__I40E_PF_RESET_REQUESTED);
+
 	/* Before we finalize any flag changes, we need to perform some
 	 * checks to ensure that the changes are supported and safe.
 	 */
@@ -5431,7 +5441,7 @@ static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
 				case LIBIE_AQ_RC_EEXIST:
 					dev_warn(&pf->pdev->dev,
 						 "FW LLDP agent is already running\n");
-					reset_needed = 0;
+					reset_needed &= ~I40E_PF_RESET_AND_REBUILD_FLAG;
 					break;
 				case LIBIE_AQ_RC_EPERM:
 					dev_warn(&pf->pdev->dev,
diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index abbc71e815ae..0a4272e1ab07 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -3458,12 +3458,7 @@ static int i40e_configure_tx_ring(struct i40e_ring *ring)
 		ring->xsk_pool = i40e_xsk_pool(ring);
 
 	/* some ATR related tx ring init */
-	if (test_bit(I40E_FLAG_FD_ATR_ENA, vsi->back->flags)) {
-		ring->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
-		ring->atr_count = 0;
-	} else {
-		ring->atr_sample_rate = 0;
-	}
+	ring->atr_count = 0;
 
 	/* configure XPS */
 	i40e_config_xps_tx_ring(ring);
@@ -12740,6 +12735,8 @@ static int i40e_sw_init(struct i40e_pf *pf)
 		}
 	}
 
+	pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
+
 	if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
 	    (pf->hw.func_caps.fd_filters_best_effort > 0)) {
 		set_bit(I40E_FLAG_FD_ATR_ENA, pf->flags);
diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.c b/drivers/net/ethernet/intel/i40e/i40e_txrx.c
index 7f68adb5109b..e045f9c71c94 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_txrx.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.c
@@ -2871,6 +2871,7 @@ static void i40e_atr(struct i40e_ring *tx_ring, struct sk_buff *skb,
 	struct tcphdr *th;
 	unsigned int hlen;
 	u32 flex_ptype, dtype_cmd;
+	u32 sample_rate;
 	int l4_proto;
 	u16 i;
 
@@ -2882,7 +2883,8 @@ static void i40e_atr(struct i40e_ring *tx_ring, struct sk_buff *skb,
 		return;
 
 	/* if sampling is disabled do nothing */
-	if (!tx_ring->atr_sample_rate)
+	sample_rate = READ_ONCE(pf->atr_sample_rate);
+	if (!sample_rate)
 		return;
 
 	/* Currently only IPv4/IPv6 with TCP is supported */
@@ -2934,7 +2936,7 @@ static void i40e_atr(struct i40e_ring *tx_ring, struct sk_buff *skb,
 	if (!th->fin &&
 	    !th->syn &&
 	    !th->rst &&
-	    (tx_ring->atr_count < tx_ring->atr_sample_rate))
+	    (tx_ring->atr_count < sample_rate))
 		return;
 
 	tx_ring->atr_count = 0;
diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.h b/drivers/net/ethernet/intel/i40e/i40e_txrx.h
index bb741ff3e5f2..be587f804e7a 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_txrx.h
+++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.h
@@ -372,8 +372,7 @@ struct i40e_ring {
 	u16 next_to_clean;
 	u16 xdp_tx_active;
 
-	u8 atr_sample_rate;
-	u8 atr_count;
+	u32 atr_count;
 
 	bool ring_active;		/* is ring online or not */
 	bool arm_wb;		/* do something to arm write back */
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net-next v2 2/2] i40e: add devlink parameter for Flow Director ATR sample rate
  2026-12-04 21:38 [PATCH net-next v2 0/2][pull request] i40e: add runtime-tunable ATR sample rate Tony Nguyen
  2026-12-04 21:38 ` [PATCH net-next v2 1/2] i40e: move ATR sample rate from ring to PF level Tony Nguyen
@ 2026-12-04 21:38 ` Tony Nguyen
  2026-12-05 22:29   ` netdev-bot+sashiko
  1 sibling, 1 reply; 5+ messages in thread
From: Tony Nguyen @ 2026-12-04 21:38 UTC (permalink / raw)
  To: davem, kuba, pabeni, edumazet, andrew+netdev, willemb, netdev
  Cc: Mohammad Heib, anthony.l.nguyen, przemyslaw.kitszel, jiri, horms,
	corbet, skhan, rdunlap, linux-doc

From: Mohammad Heib <mheib@redhat.com>

The i40e driver uses Flow Director ATR to periodically update flow
steering information for active TCP flows. The update frequency is
currently controlled by I40E_DEFAULT_ATR_SAMPLE_RATE and is fixed at
driver build time.

On systems with a large number of queues and high-rate TCP workloads,
the default sampling interval can result in frequent Flow Director
reprogramming for long-lived flows.

The amount of TCP packet reordering observed on some systems is
sensitive to the ATR sampling interval. Increasing the interval reduces
Flow Director programming activity and can significantly reduce the
associated reordering.

Since the optimal sampling interval depends on the workload and system
configuration, a single fixed value is not suitable for all deployments.

Add a devlink parameter to allow administrators to tune the ATR sample
rate at runtime without rebuilding the driver or disabling ATR
functionality entirely.

Signed-off-by: Mohammad Heib <mheib@redhat.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
---
 Documentation/networking/devlink/i40e.rst     | 21 +++++++++
 .../net/ethernet/intel/i40e/i40e_devlink.c    | 46 +++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/Documentation/networking/devlink/i40e.rst b/Documentation/networking/devlink/i40e.rst
index 51c887f0dc83..d280c17fe987 100644
--- a/Documentation/networking/devlink/i40e.rst
+++ b/Documentation/networking/devlink/i40e.rst
@@ -40,6 +40,27 @@ Parameters
 
         The default value is ``0`` (internal calculation is used).
 
+.. list-table:: Driver specific parameters implemented
+    :widths: 5 5 90
+
+    * - Name
+      - Mode
+      - Notes
+    * - ``atr_sample_rate``
+      - runtime
+      - Controls how frequently Flow Director ATR updates flow steering
+        information for active TCP flows.
+
+        ATR programs Flow Director entries based on sampled TCP packets
+        per Tx queue. The sampling interval is the number of TCP packets
+        transmitted on each queue between ATR updates.
+
+        Lower values increase Flow Director programming activity, while
+        higher values reduce the update frequency.
+
+        Setting to ``0`` disables ATR sampling (no filters will be programmed).
+
+        The default value is ``20``.
 
 Info versions
 =============
diff --git a/drivers/net/ethernet/intel/i40e/i40e_devlink.c b/drivers/net/ethernet/intel/i40e/i40e_devlink.c
index 229179ccc131..8af2487776f2 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_devlink.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_devlink.c
@@ -33,12 +33,58 @@ static int i40e_max_mac_per_vf_get(struct devlink *devlink,
 	return 0;
 }
 
+static int i40e_atr_sample_rate_set(struct devlink *devlink,
+				    u32 id,
+				    struct devlink_param_gset_ctx *ctx,
+				    struct netlink_ext_ack *extack)
+{
+	struct i40e_pf *pf = devlink_priv(devlink);
+	u32 sample_rate = ctx->val.vu32;
+
+	WRITE_ONCE(pf->atr_sample_rate, sample_rate);
+
+	/* Setting rate to 0 disables sampling but does not remove
+	 * existing ATR entries. Flush them so stale filters do not
+	 * persist on devices without HW ATR eviction.
+	 */
+	if (!sample_rate) {
+		set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
+		set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
+	}
+
+	return 0;
+}
+
+static int i40e_atr_sample_rate_get(struct devlink *devlink,
+				    u32 id,
+				    struct devlink_param_gset_ctx *ctx,
+				    struct netlink_ext_ack *extack)
+{
+	struct i40e_pf *pf = devlink_priv(devlink);
+
+	ctx->val.vu32 = READ_ONCE(pf->atr_sample_rate);
+
+	return 0;
+}
+
+enum i40e_dl_param_id {
+	I40E_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
+	I40E_DEVLINK_PARAM_ID_ATR_SAMPLE_RATE,
+};
+
 static const struct devlink_param i40e_dl_params[] = {
 	DEVLINK_PARAM_GENERIC(MAX_MAC_PER_VF,
 			      BIT(DEVLINK_PARAM_CMODE_RUNTIME),
 			      i40e_max_mac_per_vf_get,
 			      i40e_max_mac_per_vf_set,
 			      NULL),
+	DEVLINK_PARAM_DRIVER(I40E_DEVLINK_PARAM_ID_ATR_SAMPLE_RATE,
+			     "atr_sample_rate",
+			     DEVLINK_PARAM_TYPE_U32,
+			     BIT(DEVLINK_PARAM_CMODE_RUNTIME),
+			     i40e_atr_sample_rate_get,
+			     i40e_atr_sample_rate_set,
+			     NULL),
 };
 
 static void i40e_info_get_dsn(struct i40e_pf *pf, char *buf, size_t len)
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v2 1/2] i40e: move ATR sample rate from ring to PF level
  2026-12-04 21:38 ` [PATCH net-next v2 1/2] i40e: move ATR sample rate from ring to PF level Tony Nguyen
@ 2026-12-05 22:29   ` netdev-bot+sashiko
  0 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 22:29 UTC (permalink / raw)
  To: anthony.l.nguyen
  Cc: davem, kuba, pabeni, edumazet, andrew+netdev, willemb, netdev,
	mheib, przemyslaw.kitszel, jiri, horms, corbet, skhan, rdunlap,
	linux-doc

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

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

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The new 'reset_needed |= BIT(__I40E_PF_RESET_REQUESTED)' for
  ATR re-enable can be combined with I40E_PF_RESET_AND_REBUILD_FLAG,…
- [Medium] The patch removes the per-ring gate that kept ATR descriptors
  off TX queues whose HMC context had fd_ena=0.
- [Low] The patch changes the LLDP EEXIST branch of i40e_set_priv_flags()
  from 'reset_needed = 0' to 'reset_needed &=…
- [Low] Missing Fixes: tag (baseline decision: not a valid finding).

--

i40e: move ATR sample rate from ring to PF level

This moves atr_sample_rate from struct i40e_ring to struct i40e_pf. The
rate is initialized once in i40e_sw_init(), and i40e_atr() now reads the
PF-level value. It also requests a PF reset in i40e_set_priv_flags() when
ATR is re-enabled, so that fd_ena is reprogrammed in the TX queue context.

> diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> index 58d842d676422..93dd9560af7ef 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> +++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> @@ -5300,6 +5300,16 @@ static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
>  	    test_bit(I40E_FLAG_SOURCE_PRUNING_DIS, changed_flags))
>  		reset_needed = BIT(__I40E_PF_RESET_REQUESTED);
>  
> +	/* Re-enabling ATR requires a reset to reprogram fd_ena in the
> +	 * TX queue HW context. Skip when FD_SB (ntuple) is already
> +	 * enabled, since i40e_configure_tx_ring() sets fd_ena when
> +	 * either FD flag is active.
> +	 */
> +	if (test_bit(I40E_FLAG_FD_ATR_ENA, changed_flags) &&
> +	    test_bit(I40E_FLAG_FD_ATR_ENA, new_flags) &&
> +	    !test_bit(I40E_FLAG_FD_SB_ENA, new_flags))
> +		reset_needed |= BIT(__I40E_PF_RESET_REQUESTED);

[Severity: Medium]

Can this bit end up next to the I40E_PF_RESET_AND_REBUILD_FLAG that
i40e_set_priv_flags() sets earlier when the LLDP flag changes?

	if (test_bit(I40E_FLAG_FW_LLDP_DIS, changed_flags))
		reset_needed = I40E_PF_RESET_AND_REBUILD_FLAG;

i40e_do_reset() is an if/else-if chain, and it tests the PF reset bit
before the rebuild bit:

	} else if (reset_flags & I40E_PF_RESET_FLAG) {
		...
		i40e_handle_reset_warning(pf, lock_acquired);

	} else if (reset_flags & I40E_PF_RESET_AND_REBUILD_FLAG) {
		...
		i40e_prep_for_reset(pf);
		i40e_reset_and_rebuild(pf, true, lock_acquired);

If both bits are set, only i40e_handle_reset_warning() runs. That calls
i40e_reset_and_rebuild(pf, false, ...), so i40e_setup_pf_switch() never
calls i40e_vsi_reinit_setup().

The reinit=true path was added by commit 28b1208e7a7f ("i40e: Fix addition
of RX filters after enabling FW LLDP agent"). It is needed because the FW
re-initializes from NVM settings when the LLDP agent state changes.

Without that reinit, would the PF add MAC/VLAN filters while the default
switch filter is still present? That would bring back the AQ errors and
forced promiscuous mode that commit fixed.

One way to hit this, with ntuple off and ATR off:

  ethtool --set-priv-flags ethX disable-fw-lldp off flow-director-atr on

The EEXIST change below implies that both bits are expected to be set
together, but i40e_do_reset() acts on only one of them. Something similar
already happens with veb-stats, legacy-rx and disable-source-pruning, but
the ATR combination is new.

> +
>  	/* Before we finalize any flag changes, we need to perform some
>  	 * checks to ensure that the changes are supported and safe.
>  	 */
> @@ -5431,7 +5441,7 @@ static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
>  				case LIBIE_AQ_RC_EEXIST:
>  					dev_warn(&pf->pdev->dev,
>  						 "FW LLDP agent is already running\n");
> -					reset_needed = 0;
> +					reset_needed &= ~I40E_PF_RESET_AND_REBUILD_FLAG;

[Severity: Low]

This isn't a bug, but this hunk changes behavior beyond ATR, and the commit
message doesn't mention it.

Before this patch, if veb-stats, legacy-rx or disable-source-pruning changed
in the same command that re-enabled the FW LLDP agent, reset_needed held
BIT(__I40E_PF_RESET_REQUESTED). If i40e_aq_start_lldp() then returned
LIBIE_AQ_RC_EEXIST, reset_needed = 0 dropped that PF reset. With this
change the PF reset is kept.

Could the commit message mention this fix and the user-visible change?

>  					break;
>  				case LIBIE_AQ_RC_EPERM:
>  					dev_warn(&pf->pdev->dev,
> diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
> index abbc71e815ae3..0a4272e1ab070 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_main.c
> +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
> @@ -3458,12 +3458,7 @@ static int i40e_configure_tx_ring(struct i40e_ring *ring)
>  		ring->xsk_pool = i40e_xsk_pool(ring);
>  
>  	/* some ATR related tx ring init */
> -	if (test_bit(I40E_FLAG_FD_ATR_ENA, vsi->back->flags)) {
> -		ring->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
> -		ring->atr_count = 0;
> -	} else {
> -		ring->atr_sample_rate = 0;
> -	}
> +	ring->atr_count = 0;

[Severity: Low]

This isn't a bug, but the commit message describes a user-visible behavior
change and has no Fixes: tag:

  previously, re-enabling ATR via
  "ethtool --set-priv-flags ethX flow-director-atr on" did not resume
  sampling until an ifdown/ifup or PF reset

This patch is presented as a refactor in a feature series, and the next
patch, "i40e: add devlink parameter for Flow Director ATR sample rate", adds
a new devlink parameter. The old per-ring latch matched how fd_ena was
programmed, so it reads as a design limitation rather than a defect.

A Fixes: tag probably isn't needed. I'm only noting it in case one was
intended.

>  
>  	/* configure XPS */
>  	i40e_config_xps_tx_ring(ring);

[ ... ]

> diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.c b/drivers/net/ethernet/intel/i40e/i40e_txrx.c
> index 7f68adb5109b0..e045f9c71c944 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_txrx.c
> +++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.c

[ ... ]

> @@ -2882,7 +2883,8 @@ static void i40e_atr(struct i40e_ring *tx_ring, struct sk_buff *skb,
>  		return;
>  
>  	/* if sampling is disabled do nothing */
> -	if (!tx_ring->atr_sample_rate)
> +	sample_rate = READ_ONCE(pf->atr_sample_rate);
> +	if (!sample_rate)
>  		return;

[Severity: Medium]

With the per-ring latch gone from i40e_configure_tx_ring(), does anything
still stop i40e_atr() from posting filter programming descriptors on TX
queues whose HW context has fd_ena=0?

Before, ring->atr_sample_rate was non-zero only on rings that were
configured while I40E_FLAG_FD_ATR_ENA was set. That was the same step that
programmed tx_ctx.fd_ena.

Now the only gates are I40E_FLAG_FD_ATR_ENA, __I40E_FD_ATR_AUTO_DISABLED
and pf->atr_sample_rate, and pf->atr_sample_rate is non-zero by default.

i40e_set_priv_flags() publishes the new flags before it requests the reset:

	bitmap_copy(pf->flags, new_flags, I40E_PF_FLAGS_NBITS);
	...
	if (reset_needed)
		i40e_do_reset(pf, reset_needed, true);

The queues are stopped later, and fd_ena is reprogrammed only on rebuild:

  i40e_do_reset()
    i40e_handle_reset_warning()
      i40e_prep_for_reset()
        i40e_pf_quiesce_all_vsi()

__I40E_FD_ATR_AUTO_DISABLED may already be clear at that point. After the
earlier ATR disable, i40e_fdir_flush_and_replay() clears it when
fd_tcp4_filter_cnt is 0. i40e_set_ntuple() also clears it when ntuple is
turned off.

Consider this sequence while TCP traffic is flowing:

  ethtool --set-priv-flags ethX flow-director-atr off
  ethtool -K ethX ntuple off
  ethtool --set-priv-flags ethX flow-director-atr on

During that window, could i40e_xmit_frame_ring()->i40e_atr() on other CPUs
post I40E_TX_DESC_DTYPE_FILTER_PROG descriptors on queues that still have
fd_ena=0? That would happen on every SYN/FIN/RST and every sample_rate
packets.

The commit message itself says the reset is needed to reprogram fd_ena. The
code doesn't show how the hardware handles these descriptors on such
queues.

>  
>  	/* Currently only IPv4/IPv6 with TCP is supported */

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204213811.3397760-1-anthony.l.nguyen%40intel.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v2 2/2] i40e: add devlink parameter for Flow Director ATR sample rate
  2026-12-04 21:38 ` [PATCH net-next v2 2/2] i40e: add devlink parameter for Flow Director ATR sample rate Tony Nguyen
@ 2026-12-05 22:29   ` netdev-bot+sashiko
  0 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 22:29 UTC (permalink / raw)
  To: anthony.l.nguyen
  Cc: davem, kuba, pabeni, edumazet, andrew+netdev, willemb, netdev,
	mheib, przemyslaw.kitszel, jiri, horms, corbet, skhan, rdunlap,
	linux-doc

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

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

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] Writing atr_sample_rate=0 through devlink adds a second,
  undocumented way to turn ATR on and off, and the driver's existing ATR…
- [Medium] i40e_atr_sample_rate_set() requests a full hardware Flow
  Director table flush (__I40E_FD_FLUSH_REQUESTED) every time the value…
- [Medium] i40e: unsynchronized FD flush race in
  i40e_atr_sample_rate_set()
- [Low] The new atr_sample_rate entry in
  Documentation/networking/devlink/i40e.rst says "The sampling interval…

--

i40e: add devlink parameter for Flow Director ATR sample rate

This adds a runtime devlink parameter, atr_sample_rate. It sets
pf->atr_sample_rate, which i40e_atr() uses as the Flow Director ATR
sampling interval. Writing 0 disables ATR sampling and requests a Flow
Director table flush, and the parameter is documented in
Documentation/networking/devlink/i40e.rst.

> diff --git a/Documentation/networking/devlink/i40e.rst b/Documentation/networking/devlink/i40e.rst
> index 51c887f0dc833..d280c17fe987b 100644
> --- a/Documentation/networking/devlink/i40e.rst
> +++ b/Documentation/networking/devlink/i40e.rst
> @@ -40,6 +40,27 @@ Parameters

[ ... ]

> +    * - ``atr_sample_rate``
> +      - runtime
> +      - Controls how frequently Flow Director ATR updates flow steering
> +        information for active TCP flows.
> +
> +        ATR programs Flow Director entries based on sampled TCP packets
> +        per Tx queue. The sampling interval is the number of TCP packets
> +        transmitted on each queue between ATR updates.

[Severity: Low]
Is this description accurate for every TCP packet? In i40e_atr(), the
interval check is skipped for SYN packets. It is also skipped for FIN/RST
packets when I40E_FLAG_HW_ATR_EVICT_ENA is clear:

drivers/net/ethernet/intel/i40e/i40e_txrx.c:i40e_atr() {
    ...
	/* sample on all syn/fin/rst packets or once every atr sample rate */
	if (!th->fin &&
	    !th->syn &&
	    !th->rst &&
	    (tx_ring->atr_count < sample_rate))
		return;

	tx_ring->atr_count = 0;
    ...
}

Each of those packets programs an FD descriptor regardless of the rate and
resets atr_count. With many short connections, raising the value won't
reduce programming as much as this text suggests.

The parameter also has no effect while the flow-director-atr priv flag is
off, because i40e_atr() returns before it reads the rate:

	/* make sure ATR is enabled */
	if (!test_bit(I40E_FLAG_FD_ATR_ENA, pf->flags))
		return;

Could the documentation mention both cases?

[ ... ]

> diff --git a/drivers/net/ethernet/intel/i40e/i40e_devlink.c b/drivers/net/ethernet/intel/i40e/i40e_devlink.c
> index 229179ccc1319..8af2487776f28 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_devlink.c
> +++ b/drivers/net/ethernet/intel/i40e/i40e_devlink.c
> @@ -33,12 +33,58 @@ static int i40e_max_mac_per_vf_get(struct devlink *devlink,
>  	return 0;
>  }
>  
> +static int i40e_atr_sample_rate_set(struct devlink *devlink,
> +				    u32 id,
> +				    struct devlink_param_gset_ctx *ctx,
> +				    struct netlink_ext_ack *extack)
> +{
> +	struct i40e_pf *pf = devlink_priv(devlink);
> +	u32 sample_rate = ctx->val.vu32;
> +
> +	WRITE_ONCE(pf->atr_sample_rate, sample_rate);
> +
> +	/* Setting rate to 0 disables sampling but does not remove
> +	 * existing ATR entries. Flush them so stale filters do not
> +	 * persist on devices without HW ATR eviction.
> +	 */
> +	if (!sample_rate) {
> +		set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
> +		set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
> +	}

[Severity: Medium]
Can the flush requested here be lost, or finish before the ATR entries
it is meant to remove have reached the table?

i40e_atr_sample_rate_set() runs under the devlink instance lock only.
i40e_fdir_flush_and_replay() runs from the service task and i40e_atr()
runs in the Tx path. Neither of them takes that lock. The flush ends
with:

	if (!disable_atr && !pf->fd_tcp4_filter_cnt)
		clear_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
	clear_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);

Consider this ordering:

  1. CPU0 in i40e_fdir_flush_and_replay() has replayed the sideband
     filters and clears __I40E_FD_ATR_AUTO_DISABLED.
  2. CPU2 in i40e_atr() sees __I40E_FD_ATR_AUTO_DISABLED clear and
     the old non-zero pf->atr_sample_rate, and queues an ATR filter
     program descriptor.
  3. CPU1 in i40e_atr_sample_rate_set() writes 0 and sets both
     __I40E_FD_ATR_AUTO_DISABLED and __I40E_FD_FLUSH_REQUESTED.
  4. CPU0 clears __I40E_FD_FLUSH_REQUESTED.

The request from step 3 is dropped, and the entry from step 2 stays in
the FD table. With pf->atr_sample_rate at 0, i40e_atr() returns before
it would send the FIN/RST remove descriptor for that flow. On parts
without I40E_FLAG_HW_ATR_EVICT_ENA, nothing removes the entry. This is
the stale filter that the comment in this function says the flush
should prevent. The entry keeps steering the flow to the queue that was
picked when the flow was sampled.

A stale entry can also survive when no flush is already in progress.
Nothing here waits for Tx contexts that already read the old rate. An
i40e_atr() call that is past the rate check can still write a
FILTER_PROG descriptor. Descriptors already queued on a Tx ring can
also be fetched by the NIC after the CLEARFDTABLE write in
i40e_fdir_flush_and_replay().

i40e_set_priv_flags() requests the flush with the same two set_bit()
calls, so part of this may predate the patch. Should
i40e_fdir_flush_and_replay() consume the request with
test_and_clear_bit() before it clears the table? A request that arrives
during the flush would then trigger another flush. Does the zero-rate
path also need something like synchronize_net() and a Tx ring drain
before it requests the flush?

[Severity: Medium]
The comment says the flush is for devices without HW ATR eviction. Should
this code check I40E_FLAG_HW_ATR_EVICT_ENA, the previous rate, and
I40E_FLAG_FD_ATR_ENA before it sets __I40E_FD_FLUSH_REQUESTED?

As written, every write of 0 requests a full flush. That includes:

  - writing 0 when the rate is already 0
  - writing 0 while ATR is already off through the priv flag
  - writing 0 on a device that has HW eviction

The devlink core calls ->set without comparing the old and new values. Each
of these writes therefore runs i40e_fdir_flush_and_replay() again.

That function clears the whole FD table, including user ntuple/sideband
rules. It replays them only after the clear completes:

drivers/net/ethernet/intel/i40e/i40e_main.c:i40e_fdir_flush_and_replay() {
    ...
	/* flush all filters */
	wr32(&pf->hw, I40E_PFQF_CTL_1,
	     I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
    ...
		/* replay sideband filters */
		i40e_fdir_filter_restore(i40e_pf_get_main_vsi(pf));
    ...
}

Between the clear and the replay, the user's rules don't steer or drop
matching Rx traffic.

While the flag is set, i40e_add_fdir_ethtool() and i40e_del_fdir_entry()
both return -EBUSY. The flush is rate-limited by I40E_MIN_FD_FLUSH_INTERVAL
and i40e_fdir_reinit_subtask() skips it while __I40E_DOWN is set, so the
flag can stay set for a long time.

For comparison, the existing priv flag path in i40e_set_priv_flags() only
requests the flush when ATR actually goes from enabled to disabled:

	if (test_bit(I40E_FLAG_FD_ATR_ENA, changed_flags) &&
	    !test_bit(I40E_FLAG_FD_ATR_ENA, new_flags)) {
		set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
		set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
	}

[Severity: Medium]
The commit message says the parameter lets administrators tune the rate:

  "without rebuilding the driver or disabling ATR functionality entirely."

Writing 0 does disable ATR and also flushes the FD table. Should the commit
message say so?

The disable is only recorded in __I40E_FD_ATR_AUTO_DISABLED, and the rest of
the driver treats that bit as a temporary out-of-space state. For example,
i40e_fdir_flush_and_replay() clears it when the flush requested here
completes:

		i40e_fdir_filter_restore(i40e_pf_get_main_vsi(pf));
		if (!disable_atr && !pf->fd_tcp4_filter_cnt)
			clear_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);

i40e_reenable_fdir_atr() and the ntuple-off path in i40e_set_ntuple() also
clear it.

Once the bit is cleared, i40e_update_pf_stats() reports ATR as active:

	if (test_bit(I40E_FLAG_FD_ATR_ENA, pf->flags) &&
	    !test_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state))
		nsd->fd_atr_status = true;

ethtool -S then shows port.fdir_atr_status as 1, and the flow-director-atr
priv flag still shows on. Meanwhile, i40e_atr() programs no filters because
of the new check:

	sample_rate = READ_ONCE(pf->atr_sample_rate);
	if (!sample_rate)
		return;

Is it intended that neither the priv flag nor the ATR status counter
reflects atr_sample_rate == 0? A user could turn the priv flag on and still
get no ATR because the devlink value is 0.

> +
> +	return 0;
> +}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204213811.3397760-1-anthony.l.nguyen%40intel.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-05 22:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 21:38 [PATCH net-next v2 0/2][pull request] i40e: add runtime-tunable ATR sample rate Tony Nguyen
2026-12-04 21:38 ` [PATCH net-next v2 1/2] i40e: move ATR sample rate from ring to PF level Tony Nguyen
2026-12-05 22:29   ` netdev-bot+sashiko
2026-12-04 21:38 ` [PATCH net-next v2 2/2] i40e: add devlink parameter for Flow Director ATR sample rate Tony Nguyen
2026-12-05 22:29   ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox