On 12 Nov 2026, at 15:28, Eelco Chaudron via dev wrote:

> When tc_netdev_flow_put() rejects a flow because the upstream
> recirc chain is not yet registered (used_chains count is zero),
> the flow is permanently stranded in the kernel.  A new
> offload_deferred flag on struct dpif_op propagates the rejection
> up to the revalidator, which retries the offload when the offload
> state changes.
>
> An offload-specific change_seq counter signals the revalidator
> that a condition has changed which may allow successful offload.
> The revalidator will try again to offload the flow, which is
> limited to OFFLOAD_DEFERRED_MAX_RETRIES (16) attempts per ukey
> to avoid infinite loops.
>
> Fixes: 273a4fce951a ("netdev-offload-tc: Only install recirc flows if the 
> parent is present.")
> Reported-by: Numan Siddique <[email protected]>
> Signed-off-by: Eelco Chaudron <[email protected]>

Hi Numan,

Would you be able to test this version, to make sure it still covers your issue?

Thanks,

Eelco

> ---
>
> v2 changes:
>   - Use a flag to pass the deferred state, rather than EAGAIN.
>   - Fixed some style issues.
>   - Replaced the time based retry mechanism with a triggered
>     approach, with max 16 retries.
> ---
>  lib/dpif-offload-provider.h      |  5 +++
>  lib/dpif-offload-tc-netdev.c     | 32 +++++++++------
>  lib/dpif-offload-tc-private.h    |  2 +
>  lib/dpif-offload-tc.c            | 12 +++++-
>  lib/dpif-offload.c               | 28 +++++++++++++
>  lib/dpif-offload.h               |  1 +
>  lib/dpif.c                       |  7 ++++
>  lib/dpif.h                       |  3 ++
>  ofproto/ofproto-dpif-upcall.c    | 48 +++++++++++++++++++++-
>  tests/system-offloads-traffic.at | 68 ++++++++++++++++++++++++++++++++
>  10 files changed, 190 insertions(+), 16 deletions(-)
>
> diff --git a/lib/dpif-offload-provider.h b/lib/dpif-offload-provider.h
> index 0b098f6c1..c0388528e 100644
> --- a/lib/dpif-offload-provider.h
> +++ b/lib/dpif-offload-provider.h
> @@ -47,6 +47,10 @@ struct dpif_offload_provider_collection {
>                               * deletions are allowed; hence no locking of the
>                               * list is required. */
>
> +    atomic_uint64_t change_seq; /* Incremented by offload providers to signal
> +                                 * revalidators that deferred offloads should
> +                                 * be retried. */
> +
>      struct ovs_mutex mutex; /* Mutex to protect all below. */
>      struct ovs_refcount ref_cnt;
>  };
> @@ -381,6 +385,7 @@ struct dpif_offload_port 
> *dpif_offload_port_mgr_find_by_odp_port(
>
>  /* Global functions, called by the dpif layer or offload providers. */
>  void dpif_offload_module_init(void);
> +void dpif_offload_inc_change_seq(const struct dpif *);
>  void dpif_offload_set_config(struct dpif *, const struct smap *other_cfg);
>  void dpif_offload_port_add(struct dpif *, struct netdev *, odp_port_t);
>  void dpif_offload_port_del(struct dpif *, odp_port_t);
> diff --git a/lib/dpif-offload-tc-netdev.c b/lib/dpif-offload-tc-netdev.c
> index a2f4ab8b5..8d08bacde 100644
> --- a/lib/dpif-offload-tc-netdev.c
> +++ b/lib/dpif-offload-tc-netdev.c
> @@ -41,6 +41,7 @@
>  #include "unaligned.h"
>  #include "util.h"
>  #include "dpif-offload.h"
> +#include "dpif-offload-provider.h"
>  #include "dpif-offload-tc-private.h"
>  #include "dpif-provider.h"
>
> @@ -2355,17 +2356,6 @@ tc_netdev_flow_put(struct dpif *dpif, struct netdev 
> *netdev,
>      chain = key->recirc_id;
>      mask->recirc_id = 0;
>
> -    if (chain) {
> -        /* If we match on a recirculation ID, we must ensure the previous
> -         * flow is also in the TC datapath; otherwise, the entry is useless,
> -         * as the related packets will be handled by upcalls. */
> -        if (!ccmap_find(&used_chains, chain)) {
> -            VLOG_DBG_RL(&rl, "match for chain %u failed due to non-existing "
> -                        "goto chain action", chain);
> -            return EOPNOTSUPP;
> -        }
> -    }
> -
>      if (flow_tnl_dst_is_set(&key->tunnel) ||
>          flow_tnl_src_is_set(&key->tunnel)) {
>          VLOG_DBG_RL(&rl,
> @@ -2687,6 +2677,18 @@ tc_netdev_flow_put(struct dpif *dpif, struct netdev 
> *netdev,
>          return EOPNOTSUPP;
>      }
>
> +    if (chain && !ccmap_find(&used_chains, chain)) {
> +        /* If we match on a recirculation ID, we must ensure the previous
> +         * flow is also in the TC datapath; otherwise, the entry is useless,
> +         * as the related packets will be handled by upcalls.  The chain
> +         * may not be registered yet because the upstream flow install is
> +         * still in progress; flag it for deferred retry. */
> +        VLOG_DBG_RL(&rl, "match for chain %u failed due to non-existing "
> +                    "goto chain action", chain);
> +        info->offload_deferred = true;
> +        return EOPNOTSUPP;
> +    }
> +
>      memset(&adjust_stats, 0, sizeof adjust_stats);
>      if (get_ufid_tc_mapping(ufid, &id) == 0) {
>          VLOG_DBG_RL(&rl, "updating old handle: %d prio: %d",
> @@ -2725,10 +2727,16 @@ tc_netdev_flow_put(struct dpif *dpif, struct netdev 
> *netdev,
>                   * Since it does not involve recirculation handling,
>                   * it should be ignored. */
>                  if (action->type == TC_ACT_GOTO && action->chain) {
> +                    uint32_t count;
> +
>                      chain_goto = action->chain;
>                      ovs_mutex_lock(&used_chains_mutex);
> -                    ccmap_inc(&used_chains, chain_goto);
> +                    count = ccmap_inc(&used_chains, chain_goto);
>                      ovs_mutex_unlock(&used_chains_mutex);
> +                    if (count == 1) {
> +                        /* New chain registered; notify revalidators. */
> +                        dpif_offload_inc_change_seq(dpif);
> +                    }
>                      break;
>                  }
>              }
> diff --git a/lib/dpif-offload-tc-private.h b/lib/dpif-offload-tc-private.h
> index b876ff1c9..6f2e55bc9 100644
> --- a/lib/dpif-offload-tc-private.h
> +++ b/lib/dpif-offload-tc-private.h
> @@ -37,6 +37,8 @@ struct tc_offload_info {
>      bool tc_modify_flow; /* Indicates tc modified the flow. */
>      bool tc_modify_flow_deleted; /* Indicate the tc modify flow put success
>                                    * to delete the original flow. */
> +    bool offload_deferred; /* The recirc chain is not yet registered; the
> +                            * revalidator should retry the offload later. */
>  };
>
>  /* Netdev-specific offload functions.  These should only be used by the
> diff --git a/lib/dpif-offload-tc.c b/lib/dpif-offload-tc.c
> index 3b84d9f20..6f9303c57 100644
> --- a/lib/dpif-offload-tc.c
> +++ b/lib/dpif-offload-tc.c
> @@ -487,7 +487,8 @@ tc_flow_dump_thread_destroy(struct 
> dpif_offload_flow_dump_thread *thread_)
>
>  static int
>  tc_parse_flow_put(struct tc_offload *offload_tc, struct dpif *dpif,
> -                  struct dpif_flow_put *put)
> +                  struct dpif_flow_put *put,
> +                  bool *offload_deferred)
>  {
>      static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
>      struct dpif_offload_port *port;
> @@ -498,6 +499,8 @@ tc_parse_flow_put(struct tc_offload *offload_tc, struct 
> dpif *dpif,
>      size_t left;
>      int err;
>
> +    *offload_deferred = false;
> +    info.offload_deferred = false;
>      info.tc_modify_flow_deleted = false;
>      info.tc_modify_flow = false;
>
> @@ -608,6 +611,7 @@ out:
>          }
>      }
>
> +    *offload_deferred = info.offload_deferred;
>      return err;
>  }
>
> @@ -673,12 +677,16 @@ tc_operate(struct dpif *dpif, const struct dpif_offload 
> *offload_,
>          switch (op->type) {
>          case DPIF_OP_FLOW_PUT: {
>              struct dpif_flow_put *put = &op->flow_put;
> +            bool deferred = false;
>
>              if (!put->ufid) {
>                  break;
>              }
>
> -            error = tc_parse_flow_put(offload, dpif, put);
> +            error = tc_parse_flow_put(offload, dpif, put, &deferred);
> +            if (deferred) {
> +                op->offload_deferred = true;
> +            }
>              break;
>          }
>          case DPIF_OP_FLOW_DEL: {
> diff --git a/lib/dpif-offload.c b/lib/dpif-offload.c
> index 3d9a8a1fc..fce32807d 100644
> --- a/lib/dpif-offload.c
> +++ b/lib/dpif-offload.c
> @@ -274,6 +274,7 @@ dpif_attach_new_offload_provider_collection(struct dpif 
> *dpif)
>      ovs_mutex_init_recursive(&collection->mutex);
>      ovs_refcount_init(&collection->ref_cnt);
>      ovs_list_init(&collection->list);
> +    atomic_init(&collection->change_seq, 1);
>      shash_add(&dpif_offload_providers, collection->dpif_name, collection);
>
>      /* Open all the providers supporting this dpif type. */
> @@ -400,6 +401,33 @@ dpif_detach_offload_providers(struct dpif *dpif)
>      }
>  }
>
> +void
> +dpif_offload_inc_change_seq(const struct dpif *dpif)
> +{
> +    struct dpif_offload_provider_collection *collection;
> +    uint64_t old_change_seq;
> +
> +    collection = dpif_get_offload_provider_collection(dpif);
> +    ovs_assert(collection);
> +
> +    atomic_add_explicit(&collection->change_seq, 1, &old_change_seq,
> +                        memory_order_release);
> +}
> +
> +uint64_t
> +dpif_offload_get_change_seq(const struct dpif *dpif)
> +{
> +    struct dpif_offload_provider_collection *collection;
> +    uint64_t change_seq = 0;
> +
> +    collection = dpif_get_offload_provider_collection(dpif);
> +    if (collection) {
> +        atomic_read_explicit(&collection->change_seq, &change_seq,
> +                             memory_order_acquire);
> +    }
> +    return change_seq;
> +}
> +
>  void
>  dpif_offload_set_config(struct dpif *dpif, const struct smap *other_cfg)
>  {
> diff --git a/lib/dpif-offload.h b/lib/dpif-offload.h
> index b6d3c1f37..c8ba21137 100644
> --- a/lib/dpif-offload.h
> +++ b/lib/dpif-offload.h
> @@ -45,6 +45,7 @@ enum dpif_offload_impl_type {
>  void dpif_offload_set_global_cfg(const struct ovsrec_open_vswitch *);
>  bool dpif_offload_enabled(void);
>  bool dpif_offload_rebalance_policy_enabled(void);
> +uint64_t dpif_offload_get_change_seq(const struct dpif *);
>
>  
>  /* Per dpif specific functions. */
> diff --git a/lib/dpif.c b/lib/dpif.c
> index a62da6483..46f16e141 100644
> --- a/lib/dpif.c
> +++ b/lib/dpif.c
> @@ -1355,10 +1355,17 @@ dpif_operate(struct dpif *dpif, struct dpif_op **ops, 
> size_t n_ops,
>          for (i = 0; i < n_ops; i++) {
>              struct dpif_op *op = ops[i];
>              op->error = EINVAL;
> +            op->offload_deferred = false;
>          }
>          return;
>      }
>
> +    /* Initialize offload_deferred for all ops; the offload provider sets
> +     * it to true if the flow cannot be offloaded yet. */
> +    for (size_t i = 0; i < n_ops; i++) {
> +        ops[i]->offload_deferred = false;
> +    }
> +
>      while (n_ops > 0) {
>          size_t chunk;
>
> diff --git a/lib/dpif.h b/lib/dpif.h
> index 3e6a34a25..34e2dfc86 100644
> --- a/lib/dpif.h
> +++ b/lib/dpif.h
> @@ -782,6 +782,9 @@ int dpif_execute(struct dpif *, struct dpif_execute *);
>  struct dpif_op {
>      enum dpif_op_type type;
>      int error;
> +    bool offload_deferred; /* True if the offload provider requires a
> +                            * prerequisite flow to be programmed first.
> +                            * Retried when offload change_seq advances. */
>      union {
>          struct dpif_flow_put flow_put;
>          struct dpif_flow_del flow_del;
> diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c
> index c877a0c24..b082a9635 100644
> --- a/ofproto/ofproto-dpif-upcall.c
> +++ b/ofproto/ofproto-dpif-upcall.c
> @@ -51,6 +51,7 @@
>  #define UPCALL_MAX_BATCH 64
>  #define REVALIDATE_MAX_BATCH 50
>  #define UINT64_THREE_QUARTERS (UINT64_MAX / 4 * 3)
> +#define OFFLOAD_DEFERRED_MAX_RETRIES 16
>
>  VLOG_DEFINE_THIS_MODULE(ofproto_dpif_upcall);
>
> @@ -348,6 +349,9 @@ struct udpif_key {
>  #define OFFL_REBAL_INTVL_MSEC  3000  /* dynamic offload rebalance freq */
>      struct netdev *in_netdev;                /* in_odp_port's netdev */
>      bool offloaded;                  /* True if flow is offloaded */
> +    bool offload_deferred;           /* Deferred, retry next cycle. */
> +    uint64_t offload_deferred_seq;   /* change_seq when deferred. */
> +    unsigned int offload_deferred_retries; /* Retry attempts remaining. */
>      uint64_t flow_pps_rate;          /* Packets-Per-Second rate */
>      long long int flow_time;         /* last pps update time */
>      uint64_t flow_packets;           /* #pkts seen in interval */
> @@ -1685,6 +1689,7 @@ static void
>  handle_upcalls(struct udpif *udpif, struct upcall *upcalls,
>                 size_t n_upcalls)
>  {
> +    uint64_t offload_seq = dpif_offload_get_change_seq(udpif->dpif);
>      struct dpif_op *opsp[UPCALL_MAX_BATCH * 2];
>      struct ukey_op ops[UPCALL_MAX_BATCH * 2];
>      size_t n_ops, n_opsp, i;
> @@ -1745,8 +1750,16 @@ handle_upcalls(struct udpif *udpif, struct upcall 
> *upcalls,
>              ovs_mutex_lock(&ukey->mutex);
>              if (ops[i].dop.error) {
>                  transition_ukey(ukey, UKEY_EVICTED);
> -            } else if (ukey->state < UKEY_OPERATIONAL) {
> -                transition_ukey(ukey, UKEY_OPERATIONAL);
> +            } else {
> +                if (ukey->state < UKEY_OPERATIONAL) {
> +                    transition_ukey(ukey, UKEY_OPERATIONAL);
> +                }
> +                if (ops[i].dop.offload_deferred && !ukey->offload_deferred) {
> +                    ukey->offload_deferred_seq = offload_seq;
> +                    ukey->offload_deferred_retries =
> +                        OFFLOAD_DEFERRED_MAX_RETRIES;
> +                    ukey->offload_deferred = true;
> +                }
>              }
>              ovs_mutex_unlock(&ukey->mutex);
>          }
> @@ -1837,6 +1850,9 @@ ukey_create__(const struct nlattr *key, size_t key_len,
>      ukey->xcache = NULL;
>
>      ukey->offloaded = false;
> +    ukey->offload_deferred = false;
> +    ukey->offload_deferred_seq = 0;
> +    ukey->offload_deferred_retries = 0;
>      ukey->in_netdev = NULL;
>      ukey->flow_packets = ukey->flow_backlog_packets = 0;
>
> @@ -2541,6 +2557,7 @@ put_op_init(struct ukey_op *op, struct udpif_key *ukey,
>  static void
>  push_dp_ops(struct udpif *udpif, struct ukey_op *ops, size_t n_ops)
>  {
> +    uint64_t offload_seq = dpif_offload_get_change_seq(udpif->dpif);
>      struct dpif_op *opsp[REVALIDATE_MAX_BATCH];
>      size_t i;
>
> @@ -2553,6 +2570,22 @@ push_dp_ops(struct udpif *udpif, struct ukey_op *ops, 
> size_t n_ops)
>      for (i = 0; i < n_ops; i++) {
>          struct ukey_op *op = &ops[i];
>
> +        if (op->ukey && op->dop.type == DPIF_OP_FLOW_PUT) {
> +            ovs_mutex_lock(&op->ukey->mutex);
> +            if (op->dop.offload_deferred) {
> +                if (!op->ukey->offload_deferred) {
> +                    op->ukey->offload_deferred_retries =
> +                        OFFLOAD_DEFERRED_MAX_RETRIES;
> +                }
> +                op->ukey->offload_deferred_seq = offload_seq;
> +                op->ukey->offload_deferred = true;
> +            } else if (op->ukey->offload_deferred) {
> +                op->ukey->offload_deferred = false;
> +                op->ukey->offload_deferred_retries = 0;
> +            }
> +            ovs_mutex_unlock(&op->ukey->mutex);
> +        }
> +
>          if (op->dop.error) {
>              if (op->ukey) {
>                  ovs_mutex_lock(&op->ukey->mutex);
> @@ -2827,11 +2860,13 @@ revalidate(struct revalidator *revalidator)
>      struct udpif *udpif = revalidator->udpif;
>      struct dpif_flow_dump_thread *dump_thread;
>      uint64_t dump_seq, reval_seq;
> +    uint64_t offload_seq;
>      bool kill_warn_print = true;
>      unsigned int flow_limit;
>
>      dump_seq = seq_read(udpif->dump_seq);
>      reval_seq = seq_read(udpif->reval_seq);
> +    offload_seq = dpif_offload_get_change_seq(udpif->dpif);
>      atomic_read_relaxed(&udpif->flow_limit, &flow_limit);
>      dump_thread = dpif_flow_dump_thread_create(udpif->dump);
>      for (;;) {
> @@ -2985,6 +3020,15 @@ revalidate(struct revalidator *revalidator)
>                  /* Takes ownership of 'recircs'. */
>                  reval_op_init(&ops[n_ops++], result, udpif, ukey, &recircs,
>                                &odp_actions);
> +            } else if (ukey->offload_deferred) {
> +                if (offload_seq > ukey->offload_deferred_seq) {
> +                    if (ukey->offload_deferred_retries > 0) {
> +                        ukey->offload_deferred_retries--;
> +                        put_op_init(&ops[n_ops++], ukey, DPIF_FP_MODIFY);
> +                    } else {
> +                        ukey->offload_deferred = false;
> +                    }
> +                }
>              }
>              ovs_mutex_unlock(&ukey->mutex);
>          }
> diff --git a/tests/system-offloads-traffic.at 
> b/tests/system-offloads-traffic.at
> index cfcc5bd6c..aad63a8a0 100644
> --- a/tests/system-offloads-traffic.at
> +++ b/tests/system-offloads-traffic.at
> @@ -1197,6 +1197,74 @@ OVS_WAIT_WHILE(
>  OVS_TRAFFIC_VSWITCHD_STOP
>  AT_CLEANUP
>
> +AT_SETUP([offloads - split recirc rules kernel vs offload])
> +OVS_TRAFFIC_VSWITCHD_START([], [], [-- set Open_vSwitch . 
> other_config:hw-offload=true])
> +
> +ADD_NAMESPACES(at_ns0, at_ns1)
> +
> +ADD_VETH(p1, at_ns0, br0, "10.0.0.1/24")
> +ADD_VETH(p2, at_ns1, br0, "10.0.0.2/24")
> +
> +dnl Two source IPs on the same veth guarantee the same in_port and therefore
> +dnl the same recirc ID R1 for the second datapath flow.
> +NS_CHECK_EXEC([at_ns0], [ip addr add 10.0.0.3/24 dev p1])
> +
> +AT_CHECK([ovs-vsctl -- set interface ovs-p1 ofport_request=1 \
> +                    -- set interface ovs-p2 ofport_request=2])
> +
> +AT_CHECK([ovs-appctl vlog/set dpif_offload_tc_netdev:dbg])
> +
> +dnl controller() is not TC-offloadable, so both datapath flows land in 
> dp:ovs.
> +AT_DATA([flows.txt], [dnl
> +table=0,arp,actions=NORMAL
> +table=0,priority=100,in_port=ovs-p1,ip,nw_dst=10.0.0.2,actions=controller(),ct(commit,table=1)
> +table=0,priority=100,in_port=ovs-p2,ip,actions=ovs-p1
> +table=1,ip,actions=ovs-p2
> +])
> +AT_CHECK([ovs-ofctl add-flows br0 flows.txt])
> +
> +NS_CHECK_EXEC([at_ns0], [ping -q -c 3 -i 0.3 -W 2 10.0.0.2 | FORMAT_PING], 
> [0], [dnl
> +3 packets transmitted, 3 received, 0% packet loss, time 0ms
> +])
> +AT_CHECK([ovs-appctl revalidator/wait])
> +
> +AT_CHECK([grep -q "match for chain .* failed due to non-existing goto chain 
> action" \
> +          ovs-vswitchd.log])
> +AT_CHECK([ovs-appctl dpctl/dump-flows --names type=ovs \
> +          filter='in_port(ovs-p1),ipv4' | grep -c "in_port(ovs-p1)"], [0], [2
> +])
> +AT_CHECK([ovs-appctl dpctl/dump-flows --names type=tc \
> +          filter='in_port(ovs-p1),ipv4'], [0], [dnl
> +])
> +
> +dnl Replace the rule with plain ct (TC-offloadable).  Traffic from 10.0.0.3
> +dnl offloads its first datapath flow to dp:tc, which registers the recirc ID.
> +dnl After the fix, the second datapath flow should also be offloaded to 
> dp:tc.
> +AT_CHECK([ovs-ofctl del-flows br0 
> "table=0,in_port=ovs-p1,ip,nw_dst=10.0.0.2"])
> +AT_DATA([flows2.txt], [dnl
> +table=0,priority=100,in_port=ovs-p1,ip,nw_dst=10.0.0.2,actions=ct(commit,table=1)
> +])
> +AT_CHECK([ovs-ofctl add-flows br0 flows2.txt])
> +
> +NS_CHECK_EXEC([at_ns0], [ping -q -c 3 -i 0.3 -W 2 -I 10.0.0.3 10.0.0.2 | 
> FORMAT_PING], [0], [dnl
> +3 packets transmitted, 3 received, 0% packet loss, time 0ms
> +])
> +
> +AT_CHECK([ovs-appctl revalidator/wait])
> +OVS_WAIT_UNTIL([ovs-appctl dpctl/dump-flows --names type=tc \
> +    filter='in_port(ovs-p1),ipv4' | grep -q "actions:ovs-p2"])
> +
> +AT_CHECK([ovs-appctl dpctl/dump-flows --names type=tc \
> +          filter='in_port(ovs-p1),ipv4' | grep -c "in_port(ovs-p1)"], [0], [2
> +])
> +AT_CHECK([ovs-appctl dpctl/dump-flows --names type=ovs \
> +          filter='in_port(ovs-p1),ipv4' | grep "actions:ovs-p2"], [1])
> +AT_CHECK([ovs-appctl dpctl/dump-flows --names type=tc \
> +          filter='in_port(ovs-p1),ipv4' | grep "actions:ovs-p2"], [0], 
> [ignore])
> +
> +OVS_TRAFFIC_VSWITCHD_STOP
> +AT_CLEANUP
> +
>  AT_SETUP([offloads - ovs-appctl dpif/offload/show - offloads enabled])
>  AT_KEYWORDS([dpif-offload])
>  OVS_TRAFFIC_VSWITCHD_START([], [],
> -- 
> 2.56.0
>
> _______________________________________________
> dev mailing list
> [email protected]
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to