AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/07/16 04:38 flow patch-triage
0m Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [
    "flow_dissect_fast",
    "flow_dissect_fast_ipv4",
    "flow_dissect_fast_ipv6",
    "flow_dissect_fast_vlan",
    "flow_dissect_fast_pppoe",
    "flow_dissect_fast_mpls",
    "flow_dissect_fast_ipip_inner",
    "flow_dissect_fast_gre_inner",
    "proc_set_vlan_key",
    "proc_set_qinq_key"
  ],
  "Reasoning": "The patch introduces opt-in fast paths for the network flow dissector. This is reachable core network logic that processes untrusted packet data, making it a prime target for fuzzing to ensure memory safety and correctness of the new parsing logic.",
  "WorthFuzzing": true
}

1/1 2026/07/16 04:38 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit fa4cb94e8670a4e763d6397cd01731732e29dc14\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Thu Jul 16 04:38:04 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/Documentation/admin-guide/sysctl/net.rst b/Documentation/admin-guide/sysctl/net.rst\nindex e586e17fc7a582..3b55b2528ba2ed 100644\n--- a/Documentation/admin-guide/sysctl/net.rst\n+++ b/Documentation/admin-guide/sysctl/net.rst\n@@ -460,7 +460,183 @@ historical importance.\n \n Default: 0\n \n-2. /proc/sys/net/unix - Parameters for Unix domain sockets\n+2. /proc/sys/net/flow_dissector - Flow dissector fast-path per-shape sysctls\n+---------------------------------------------------------------------------\n+\n+The flow dissector is invoked on every packet that needs a flow hash\n+(RPS, RFS, ECMP, sch_cake, cls_flower, ...). For common shapes\n+(Eth+IPv4/IPv6+TCP/UDP, plus per-shape extensions for VLAN/QinQ,\n+PPPoE, MPLS, IP-in-IP and GRE added by this series), an opt-in\n+fast-path bypasses the slow-path graph walk and writes\n+``struct flow_keys`` directly. Each shape is gated by its own static\n+key + sysctl so operators enable only what their deployment uses.\n+\n+All defaults are 0 (off). Flipping any of these on takes effect\n+immediately; no kernel rebuild needed.\n+\n+eth_ip\n+~~~~~~\n+\n+Eth + IPv4 (IHL=5, no fragmentation) + TCP/UDP, and Eth + IPv6 (no\n+extension headers) + TCP/UDP. Output is byte-identical to the slow\n+path on the eligible shape; non-matching packets fall through to the\n+slow path unchanged. The dispatcher costs one not-taken JMP per call\n+when this is 0.\n+\n+Default: 0\n+\n+vlan\n+~~~~\n+\n+Single 802.1Q or 802.1AD tagged frames over Eth + IPv4/IPv6 +\n+TCP/UDP. Handles both the hardware-stripped form (tag in skb\n+metadata, inner ethertype in skb-\u003eprotocol) and the in-band form\n+(4-byte vlan_hdr at data + nhoff). Writes FLOW_DISSECTOR_KEY_VLAN\n+and bumps FLOW_DISSECTOR_KEY_NUM_OF_VLANS when those keys are\n+requested by the dissector. Byte-identical with the slow path for\n+the eligible shape; defers on any miss (QinQ defers; see the qinq\n+sysctl).\n+\n+Default: 0\n+\n+qinq\n+~~~~\n+\n+Lifts the vlan fast-path's depth limit from 1 to 2 so two stacked\n+802.1AD / 802.1Q tags (canonical QinQ S-tag + C-tag, or two stacked\n+802.1Q tags) are also fast-pathed. Outer tag is written to\n+FLOW_DISSECTOR_KEY_VLAN, inner to FLOW_DISSECTOR_KEY_CVLAN, mirroring\n+the slow-path's MAX → VLAN → CVLAN state machine. Byte-identical\n+with the slow path for the eligible shape.\n+\n+Auto-toggle: writing qinq=1 also enables vlan (QinQ extends VLAN;\n+the depth-0 entry of the helper is gated by the vlan key). Turning\n+vlan off (writing 0) also clears qinq (depth-2 cannot fire when\n+the outer entry is off).\n+\n+Default: 0\n+\n+pppoe\n+~~~~~\n+\n+PPPoE session frames (RFC 2516, EtherType ``ETH_P_PPP_SES`` 0x8864)\n+carrying IPv4 or IPv6 inside PPP. The fast-path strips the 6-byte\n+PPPoE session header + 2-byte PPP protocol field, writes\n+FLOW_DISSECTOR_KEY_PPPOE (session_id, ppp_proto, type) when the\n+dissector requests it, and tail-calls into the eth_ip fast-path for\n+the inner IPv4 / IPv6 + TCP/UDP. Byte-identical with the slow path\n+for the eligible shape.\n+\n+Defers to slow path for: PPP_MPLS_UC / PPP_MPLS_MC (until an MPLS\n+fast-path lands), PFC-compressed PPP protocol fields, LCP/IPCP/etc.\n+control frames, and any malformed PPPoE header (ver != 1, type != 1,\n+code != 0).\n+\n+Default: 0\n+\n+mpls\n+~~~~\n+\n+Single-label MPLS frames (EtherType ``ETH_P_MPLS_UC`` 0x8847 or\n+``ETH_P_MPLS_MC`` 0x8848 with bottom-of-stack bit set on the first\n+label). The fast-path reads the 4-byte label entry, extracts\n+label / TC / TTL / BoS, and writes them to FLOW_DISSECTOR_KEY_MPLS\n+lse[0] when requested. Byte-identical with the slow path's\n+__skb_flow_dissect_mpls() for lse_index=0, bos=1: the slow path\n+returns OUT_GOOD on BoS without descending into the inner packet\n+(MPLS hashing is on the label stack, not inner 5-tuple), so this\n+fast-path does the same.\n+\n+Multi-label stacks (BoS=0 on the first label) defer to slow path —\n+extending to depth-2 or more is a follow-up, mirroring the\n+vlan -\u003e qinq staging used earlier in this series.\n+\n+Default: 0\n+\n+ipip\n+~~~~\n+\n+IPv4-in-IPv4 (``IPPROTO_IPIP`` 4), IPv6-in-IPv4 (``IPPROTO_IPV6`` 41\n+inside an IPv4 outer), IPv4-in-IPv6 and IPv6-in-IPv6 tunnels. When\n+the outer IP fast-path notices the outer protocol/nexthdr is one of\n+these and this gate is on, it skips the outer header and tail-calls\n+into the inner IPv4 / IPv6 fast-path. The flow_keys ends up with the\n+inner 5-tuple (matching the slow path's behaviour, where the inner\n+parse overwrites the outer addrs/basic), plus\n+FLOW_DIS_ENCAPSULATION set on key_control-\u003eflags.\n+\n+Byte-identical with the slow path's IPPROTO_IPIP / IPPROTO_IPV6\n+switch cases for the eligible shape. Defers on any miss — including\n+fragmented outer, unusual outer IHL, or unsupported inner shapes\n+that the inner IP fast-path itself would defer.\n+\n+Default: 0\n+\n+gre\n+~~~\n+\n+GRE-encapsulated inner IP (``IPPROTO_GRE`` 47). The fast-path\n+mirrors the slow path's __skb_flow_dissect_gre() descent for the\n+common subset:\n+\n+- GRE version 0 (the v1 PPTP variant defers to slow path)\n+- All GRE flags clear (no GRE_CSUM, GRE_KEY, GRE_SEQ, GRE_ROUTING —\n+  i.e. plain 4-byte GRE base header)\n+- protocol field is ``ETH_P_IP`` 0x0800 or ``ETH_P_IPV6`` 0x86DD\n+  (no Transparent Ethernet Bridging, no PPP-over-GRE, no MPLS-\n+  over-GRE)\n+\n+In that subset, slow path also descends to inner IP and stamps\n+``key_control-\u003eflags |= FLOW_DIS_ENCAPSULATION``; the fast-path\n+produces the same output.\n+\n+GRE-with-KEY (common in MPLS-over-GRE deployments and some cloud\n+overlays) is a follow-up patch — same descent shape with an\n+additional 4-byte key field read and a write to\n+``FLOW_DISSECTOR_KEY_GRE_KEYID``.\n+\n+Default: 0\n+\n+The ``/proc/net/flow_dissector_stats`` observability file\n+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n+\n+Read-only. Reports, per byte-identical shape, the number of packets the\n+slow path handled (``occurrences``), the number the fast body handled\n+(``fast_hits``), the resulting eligible fraction, and the current gate\n+state, plus a total dissect count. Because the fast path returns before\n+the slow-path classification, exactly one of the two counters is\n+incremented per shaped packet depending on gate state, so\n+``(occurrences + fast_hits) / dissects`` is a gate-invariant measure of\n+how much traffic each shape's fast body would handle -- the signal an\n+operator uses to decide whether a gate is worth enabling. The slow-path\n+counts sit at protocol recognition points, a superset of fast-path\n+eligibility (a VLAN+ARP frame counts as vlan), so the eligible fraction\n+is an upper bound; the exact hit rate once a gate is on is\n+``fast_hits / (occurrences + fast_hits)``. The counters\n+are per-cpu and summed on read; the per-packet cost is one increment on\n+the already-hot classification path.\n+\n+An example snapshot, from a host that mostly sees plain Eth + IP traffic\n+with some VLAN, before any gate has been enabled::\n+\n+  # cat /proc/net/flow_dissector_stats\n+  shape         occurrences        fast_hits  eligible%  gate\n+  eth_ip            1866909                0      75.71   off\n+  vlan               598847                0      24.28   off\n+  qinq                    0                0       0.00   off\n+  pppoe                   0                0       0.00   off\n+  mpls                    0                0       0.00   off\n+  ipip                    0                0       0.00   off\n+  gre                     0                0       0.00   off\n+  dissects: 2465765\n+\n+Read top-down: 76% of dissects are plain Eth + IP and 24% are\n+VLAN-tagged, so ``eth_ip`` and ``vlan`` are the shapes worth enabling on\n+this host; the other shapes are absent. Every gate is still off, so all\n+the traffic sits under ``occurrences``; enabling a gate moves that\n+shape's packets to ``fast_hits``.\n+\n+3. /proc/sys/net/unix - Parameters for Unix domain sockets\n ----------------------------------------------------------\n \n There is only one file in this directory.\ndiff --git a/Documentation/bpf/index.rst b/Documentation/bpf/index.rst\nindex 0d5c6f6592667a..6e26731fa06fd7 100644\n--- a/Documentation/bpf/index.rst\n+++ b/Documentation/bpf/index.rst\n@@ -23,6 +23,7 @@ that goes into great technical depth about the BPF Architecture.\n    cpumasks\n    fs_kfuncs\n    programs\n+   prog_flow_dissector\n    maps\n    bpf_prog_run\n    classic_vs_extended.rst\ndiff --git a/Documentation/bpf/prog_flow_dissector.rst b/Documentation/bpf/prog_flow_dissector.rst\nindex f24270b8b0343c..f4c4648461ca83 100644\n--- a/Documentation/bpf/prog_flow_dissector.rst\n+++ b/Documentation/bpf/prog_flow_dissector.rst\n@@ -9,6 +9,8 @@ Overview\n \n Flow dissector is a routine that parses metadata out of the packets. It's\n used in the various places in the networking subsystem (RFS, flow hash, etc).\n+See :doc:`/networking/flow_dissector` for an overview of the flow dissector\n+and the built-in C implementation this program type overrides.\n \n BPF flow dissector is an attempt to reimplement C-based flow dissector logic\n in BPF to gain all the benefits of BPF verifier (namely, limits on the\ndiff --git a/Documentation/networking/flow_dissector.rst b/Documentation/networking/flow_dissector.rst\nnew file mode 100644\nindex 00000000000000..014f6d124b4fc2\n--- /dev/null\n+++ b/Documentation/networking/flow_dissector.rst\n@@ -0,0 +1,133 @@\n+.. SPDX-License-Identifier: GPL-2.0\n+\n+==============\n+Flow Dissector\n+==============\n+\n+Overview\n+========\n+\n+The flow dissector parses a packet's headers into a ``struct flow_keys``: the\n+addresses, ports, and other fields that identify the flow the packet belongs\n+to. Its entry point is ``__skb_flow_dissect()`` in\n+``net/core/flow_dissector.c``.\n+\n+The dissected keys feed ``skb-\u003ehash`` (via ``flow_hash_from_keys()``), which is\n+the canonical flow identity consumed all over the stack, including:\n+\n+* receive-side steering: RSS, RPS, RFS and accelerated RFS (aRFS);\n+* transmit-side spreading: ECMP / multipath route selection and bonding / LAG\n+  ``xmit_hash_policy``;\n+* classification and offload: tc-flower.\n+\n+A single dissection therefore feeds every one of these, so the dissector sits\n+on a hot path in most networking workloads.\n+\n+Two standard dissectors are built in: ``flow_keys_dissector`` (the general one)\n+and ``flow_keys_dissector_symmetric`` (same source and destination hashed\n+symmetrically). In addition, subsystems such as tc-flower build **custom**\n+dissector instances at run time that request only the keys they need. A custom\n+instance carries its own ``used_keys`` bitmask and per-key offset table, so its\n+field accesses are resolved dynamically at each dissect.\n+\n+struct flow_keys\n+================\n+\n+``struct flow_keys`` (see ``include/net/flow_dissector.h``) collects the\n+dissected metadata. Its main members are:\n+\n+* ``control`` -- address type and control flags (for example\n+  ``FLOW_DIS_ENCAPSULATION`` when the keys came from inside a tunnel, and\n+  ``FLOW_DIS_IS_FRAGMENT``);\n+* ``basic`` -- L3 protocol (``n_proto``) and L4 protocol (``ip_proto``);\n+* ``addrs`` -- source and destination addresses (IPv4 or IPv6);\n+* ``ports`` -- source and destination ports;\n+* ``vlan`` / ``cvlan`` -- 802.1Q / 802.1AD tags;\n+* ``tags``, ``keyid``, ``icmp`` -- MPLS/flow-label tags, GRE/tunnel key, and\n+  ICMP identifiers.\n+\n+The dissection path\n+===================\n+\n+The built-in dissector is a generic protocol-graph parser: it walks the header\n+chain in a loop, dispatching on the current L2/L3 ethertype and then the L4\n+protocol, following encapsulation (IP-in-IP, GRE, ...) by re-entering the loop\n+on the inner header. The number of headers it will descend through is bounded\n+by ``MAX_FLOW_DISSECT_HDRS`` so that a crafted deeply nested packet cannot make\n+it loop without limit.\n+\n+This generic parser is referred to below as the *slow path*: it is table- and\n+loop-driven and handles every protocol the dissector knows about.\n+\n+The BPF flow dissector\n+======================\n+\n+A per-network-namespace BPF program can be attached to replace the built-in\n+dissector for the protocols it chooses to handle. When one is attached,\n+``__skb_flow_dissect()`` runs it **first**; if the program returns a verdict\n+other than ``BPF_FLOW_DISSECTOR_CONTINUE``, its result is used and the built-in\n+dissector (including the fast paths below) is not run for that packet. A system\n+running an attached BPF dissector therefore sees behaviour defined entirely by\n+its program.\n+\n+See :doc:`/bpf/prog_flow_dissector` for the BPF program type, its API, and its\n+reference implementation.\n+\n+Opt-in fast paths\n+=================\n+\n+For the packet shapes that dominate real deployments, the built-in dissector\n+also provides an opt-in, straight-line *fast path* that produces the same\n+result as the slow-path graph walk with far fewer instructions. Restricting the\n+fast path to the two standard dissectors turns their per-key offsets into\n+compile-time constants, so the parse becomes branch-light straight-line code;\n+the isolated per-dissect cost of the eligible shapes drops by roughly half,\n+with the largest wins on in-order cores.\n+\n+Each shape has its own gate -- a ``static_branch`` exposed as a sysctl under\n+``/proc/sys/net/flow_dissector/`` -- and **every gate is off by default**. When\n+a gate is off, the only added cost is one not-taken branch per dissect, and the\n+dissector's output is exactly what it was before. The fast path runs only\n+*after* the BPF hook described above, so an attached BPF program always takes\n+precedence.\n+\n+The fast paths are **byte-identical by contract**: for any packet, a fast path\n+either writes exactly the ``flow_keys`` the slow path would have written, or it\n+returns false and the slow path runs. There are only these two outcomes, and\n+the equivalence is enforced in-tree by a KUnit test suite\n+(``CONFIG_FLOW_DISSECTOR_KUNIT_TEST``). Enabling a byte-identical shape gate\n+never changes any consumer's hash; it only makes the dissection cheaper.\n+\n+The eligible byte-identical shapes are plain Ethernet + IPv4/IPv6 + TCP/UDP,\n+single and stacked VLAN (QinQ), PPPoE sessions, a single MPLS label, the\n+IP-in-IP family, and plain GRE. The individual knobs are documented in\n+:doc:`/admin-guide/sysctl/net` under ``/proc/sys/net/flow_dissector``.\n+\n+When to enable\n+==============\n+\n+Turning a byte-identical shape gate on is worthwhile when enough traffic matches\n+that shape to repay the small cost a non-matching packet pays while the gate is\n+on. Concretely, if a matching packet saves ``S`` and a non-matching packet costs\n+``C`` (both measured per shape and per micro-architecture), enabling the gate is\n+net-positive once the fraction of traffic matching the shape exceeds the\n+break-even ``p_be = C / (S + C)``.\n+\n+That fraction is observable: the read-only file\n+``/proc/net/flow_dissector_stats`` reports, per shape, how many packets the slow\n+path handled, how many the fast body handled, and the resulting eligible\n+fraction, so ``(occurrences + fast_hits) / dissects`` is a gate-invariant\n+measure of how much traffic each shape would accelerate.\n+\n+A separate RFC proposes an optional ``auto`` mode built on these counters: the\n+kernel would sample them over a packet-count window and flip the\n+byte-identical gates itself, with hysteresis and a flip-rate cap, so the\n+operator does not have to tune each shape by hand. That controller is not part\n+of this series.\n+\n+References\n+==========\n+\n+* :doc:`/admin-guide/sysctl/net` -- the ``/proc/sys/net/flow_dissector/``\n+  per-shape knob reference and the ``/proc/net/flow_dissector_stats`` file.\n+* :doc:`/bpf/prog_flow_dissector` -- the BPF flow dissector program type.\ndiff --git a/Documentation/networking/index.rst b/Documentation/networking/index.rst\nindex 44a422ad3b0553..65368050ebab69 100644\n--- a/Documentation/networking/index.rst\n+++ b/Documentation/networking/index.rst\n@@ -52,6 +52,7 @@ Contents:\n    eql\n    fib_trie\n    filter\n+   flow_dissector\n    generic-hdlc\n    generic_netlink\n    ../netlink/specs/index\ndiff --git a/include/linux/skbuff.h b/include/linux/skbuff.h\nindex 22eda1d54a0e84..6448c59dc80784 100644\n--- a/include/linux/skbuff.h\n+++ b/include/linux/skbuff.h\n@@ -1588,6 +1588,7 @@ void skb_flow_dissector_init(struct flow_dissector *flow_dissector,\n \t\t\t     unsigned int key_count);\n \n struct bpf_flow_dissector;\n+extern struct static_key_false netns_bpf_flow_dissector_enabled;\n u32 bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,\n \t\t     __be16 proto, int nhoff, int hlen, unsigned int flags);\n \ndiff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h\nindex ced79dc8e8560e..b92aef8039f8de 100644\n--- a/include/net/flow_dissector.h\n+++ b/include/net/flow_dissector.h\n@@ -425,6 +425,40 @@ __be32 flow_get_u32_dst(const struct flow_keys *flow);\n extern struct flow_dissector flow_keys_dissector;\n extern struct flow_dissector flow_keys_basic_dissector;\n \n+/* Per-shape fast-path static-branch keys, toggled via\n+ * /proc/sys/net/flow_dissector/\u003cshape\u003e. All default off.\n+ */\n+extern struct static_key_false flow_dissector_eth_ip_key;\n+extern struct static_key_false flow_dissector_vlan_key;\n+extern struct static_key_false flow_dissector_qinq_key;\n+extern struct static_key_false flow_dissector_pppoe_key;\n+extern struct static_key_false flow_dissector_mpls_key;\n+extern struct static_key_false flow_dissector_ipip_key;\n+extern struct static_key_false flow_dissector_gre_key;\n+\n+/* Per-shape counters for /proc/net/flow_dissector_stats.\n+ * occurrences[]: shape seen by the slow path (the eligible-fraction\n+ * signal while its gate is off); fast_hits[]: fast path ran.\n+ * Byte-identical shapes only; the behaviour-changing descents are\n+ * never counted or auto-managed.\n+ */\n+enum flow_dissector_shape {\n+\tFLOW_DISSECTOR_SHAPE_ETH_IP,\n+\tFLOW_DISSECTOR_SHAPE_VLAN,\n+\tFLOW_DISSECTOR_SHAPE_QINQ,\n+\tFLOW_DISSECTOR_SHAPE_PPPOE,\n+\tFLOW_DISSECTOR_SHAPE_MPLS,\n+\tFLOW_DISSECTOR_SHAPE_IPIP,\n+\tFLOW_DISSECTOR_SHAPE_GRE,\n+\tFLOW_DISSECTOR_SHAPE__MAX,\n+};\n+\n+#if IS_ENABLED(CONFIG_FLOW_DISSECTOR_KUNIT_TEST)\n+/* Test-only accessors, defined in flow_dissector.c. */\n+struct flow_dissector *flow_keys_dissector_symmetric_kunit(void);\n+u64 flow_dissector_fast_hits_kunit(void);\n+#endif\n+\n /* struct flow_keys_digest:\n  *\n  * This structure is used to hold a digest of the full flow keys. This is a\ndiff --git a/kernel/bpf/net_namespace.c b/kernel/bpf/net_namespace.c\nindex 25f30f9edaefd3..0d48ea65697e56 100644\n--- a/kernel/bpf/net_namespace.c\n+++ b/kernel/bpf/net_namespace.c\n@@ -28,6 +28,9 @@ DEFINE_MUTEX(netns_bpf_mutex);\n static void netns_bpf_attach_type_unneed(enum netns_bpf_attach_type type)\n {\n \tswitch (type) {\n+\tcase NETNS_BPF_FLOW_DISSECTOR:\n+\t\tstatic_branch_dec(\u0026netns_bpf_flow_dissector_enabled);\n+\t\tbreak;\n #ifdef CONFIG_INET\n \tcase NETNS_BPF_SK_LOOKUP:\n \t\tstatic_branch_dec(\u0026bpf_sk_lookup_enabled);\n@@ -41,6 +44,9 @@ static void netns_bpf_attach_type_unneed(enum netns_bpf_attach_type type)\n static void netns_bpf_attach_type_need(enum netns_bpf_attach_type type)\n {\n \tswitch (type) {\n+\tcase NETNS_BPF_FLOW_DISSECTOR:\n+\t\tstatic_branch_inc(\u0026netns_bpf_flow_dissector_enabled);\n+\t\tbreak;\n #ifdef CONFIG_INET\n \tcase NETNS_BPF_SK_LOOKUP:\n \t\tstatic_branch_inc(\u0026bpf_sk_lookup_enabled);\n@@ -352,6 +358,11 @@ int netns_bpf_prog_attach(const union bpf_attr *attr, struct bpf_prog *prog)\n \tnet-\u003ebpf.progs[type] = prog;\n \tif (attached)\n \t\tbpf_prog_put(attached);\n+\telse\n+\t\t/* Mark attach point as used on a fresh attach; a\n+\t\t * replacement keeps the existing count.\n+\t\t */\n+\t\tnetns_bpf_attach_type_need(type);\n \n out_unlock:\n \tmutex_unlock(\u0026netns_bpf_mutex);\n@@ -373,6 +384,8 @@ static int __netns_bpf_prog_detach(struct net *net,\n \tattached = net-\u003ebpf.progs[type];\n \tif (!attached || attached != old)\n \t\treturn -ENOENT;\n+\t/* Mark attach point as unused */\n+\tnetns_bpf_attach_type_unneed(type);\n \tnetns_bpf_run_array_detach(net, type);\n \tnet-\u003ebpf.progs[type] = NULL;\n \tbpf_prog_put(attached);\n@@ -546,8 +559,10 @@ static void __net_exit netns_bpf_pernet_pre_exit(struct net *net)\n \t\t\tnet_link-\u003enet = NULL; /* auto-detach link */\n \t\t\tnetns_bpf_attach_type_unneed(type);\n \t\t}\n-\t\tif (net-\u003ebpf.progs[type])\n+\t\tif (net-\u003ebpf.progs[type]) {\n+\t\t\tnetns_bpf_attach_type_unneed(type);\n \t\t\tbpf_prog_put(net-\u003ebpf.progs[type]);\n+\t\t}\n \t}\n \tmutex_unlock(\u0026netns_bpf_mutex);\n }\ndiff --git a/net/Kconfig b/net/Kconfig\nindex e384773935515d..d0ce8fc344290c 100644\n--- a/net/Kconfig\n+++ b/net/Kconfig\n@@ -540,4 +540,16 @@ config NET_TEST\n \n \t  If unsure, say N.\n \n+config FLOW_DISSECTOR_KUNIT_TEST\n+\ttristate \"KUnit tests for flow dissector fast/slow path equivalence\" if !KUNIT_ALL_TESTS\n+\tdepends on KUNIT\n+\tdefault KUNIT_ALL_TESTS\n+\thelp\n+\t  KUnit tests asserting the flow dissector's opt-in per-shape\n+\t  fast paths produce byte-identical struct flow_keys output to\n+\t  the slow path for every corpus packet, with the gates on and\n+\t  off.\n+\n+\t  If unsure, say N.\n+\n endif   # if NET\ndiff --git a/net/core/Makefile b/net/core/Makefile\nindex b3fdcb4e355fa6..b27c69580d2ca0 100644\n--- a/net/core/Makefile\n+++ b/net/core/Makefile\n@@ -46,6 +46,7 @@ obj-$(CONFIG_BPF_SYSCALL) += sock_map.o\n obj-$(CONFIG_BPF_SYSCALL) += bpf_sk_storage.o\n obj-$(CONFIG_OF)\t+= of_net.o\n obj-$(CONFIG_NET_TEST) += net_test.o\n+obj-$(CONFIG_FLOW_DISSECTOR_KUNIT_TEST) += flow_dissector_test.o\n obj-$(CONFIG_NET_DEVMEM) += devmem.o\n obj-$(CONFIG_DEBUG_NET) += lock_debug.o\n obj-$(CONFIG_FAIL_SKB_REALLOC) += skb_fault_injection.o\ndiff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c\nindex 8aa4f9b4df8101..aaed4473c211e2 100644\n--- a/net/core/flow_dissector.c\n+++ b/net/core/flow_dissector.c\n@@ -36,6 +36,92 @@\n #include \u003cnet/netfilter/nf_conntrack_labels.h\u003e\n #endif\n #include \u003clinux/bpf-netns.h\u003e\n+#include \u003clinux/proc_fs.h\u003e\n+#include \u003clinux/seq_file.h\u003e\n+#include \u003clinux/string_choices.h\u003e\n+#include \u003clinux/math64.h\u003e\n+\n+/* Per-shape fast-path gates, one static_branch per shape so operators\n+ * enable only what their deployment carries. All default off.\n+ */\n+DEFINE_STATIC_KEY_FALSE(flow_dissector_eth_ip_key);\n+EXPORT_SYMBOL(flow_dissector_eth_ip_key);\n+DEFINE_STATIC_KEY_FALSE(flow_dissector_vlan_key);\n+EXPORT_SYMBOL(flow_dissector_vlan_key);\n+DEFINE_STATIC_KEY_FALSE(flow_dissector_qinq_key);\n+EXPORT_SYMBOL(flow_dissector_qinq_key);\n+DEFINE_STATIC_KEY_FALSE(flow_dissector_pppoe_key);\n+EXPORT_SYMBOL(flow_dissector_pppoe_key);\n+DEFINE_STATIC_KEY_FALSE(flow_dissector_mpls_key);\n+EXPORT_SYMBOL(flow_dissector_mpls_key);\n+DEFINE_STATIC_KEY_FALSE(flow_dissector_ipip_key);\n+EXPORT_SYMBOL(flow_dissector_ipip_key);\n+DEFINE_STATIC_KEY_FALSE(flow_dissector_gre_key);\n+EXPORT_SYMBOL(flow_dissector_gre_key);\n+\n+/* Per-cpu, summed on read via /proc/net/flow_dissector_stats.\n+ * occurrences[]: shape handled by the slow path (with the gate off,\n+ * the shape's eligible-fraction signal); fast_hits[]: fast body ran;\n+ * dissects: denominator.\n+ */\n+struct flow_dissector_stats {\n+\tu64 occurrences[FLOW_DISSECTOR_SHAPE__MAX];\n+\tu64 fast_hits[FLOW_DISSECTOR_SHAPE__MAX];\n+\tu64 dissects;\n+};\n+\n+static DEFINE_PER_CPU(struct flow_dissector_stats, flow_dissector_pcpu_stats);\n+\n+static inline void flow_dissector_count_slow(enum flow_dissector_shape shape)\n+{\n+\tthis_cpu_inc(flow_dissector_pcpu_stats.occurrences[shape]);\n+}\n+\n+static inline void flow_dissector_count_fast(enum flow_dissector_shape shape)\n+{\n+\tthis_cpu_inc(flow_dissector_pcpu_stats.fast_hits[shape]);\n+}\n+\n+/* Counting map: eth_ip counts in the dispatcher (only when the leaf\n+ * did not set ENCAP), vlan/qinq/pppoe/mpls in their helpers, ipip/gre\n+ * in the inner-descent helpers. The slow path counts where it\n+ * recognises each shape, gate on or off.\n+ */\n+\n+/* IPv4 version/IHL byte of an option-less header: version 4, IHL 5. */\n+#define FLOW_DIS_IPV4_VIHL_NOOPT\t0x45\n+\n+/* @num_hdrs: protocol headers consumed so far (Ethernet = 1, each VLAN\n+ * tag, each outer IP header). Tunnel descents increment it and defer\n+ * past MAX_FLOW_DISSECT_HDRS, so both paths stop at the same depth.\n+ */\n+static bool flow_dissect_fast_ipv4(const struct sk_buff *skb,\n+\t\t\t\t   struct flow_dissector *flow_dissector,\n+\t\t\t\t   void *target_container,\n+\t\t\t\t   const void *data,\n+\t\t\t\t   int nhoff, int hlen, int num_hdrs);\n+static bool flow_dissect_fast_ipv6(const struct sk_buff *skb,\n+\t\t\t\t   struct flow_dissector *flow_dissector,\n+\t\t\t\t   void *target_container,\n+\t\t\t\t   const void *data,\n+\t\t\t\t   int nhoff, int hlen, int num_hdrs);\n+static bool flow_dissect_fast_ipip_inner(const struct sk_buff *skb,\n+\t\t\t\t\t struct flow_dissector *flow_dissector,\n+\t\t\t\t\t void *target_container,\n+\t\t\t\t\t const void *data,\n+\t\t\t\t\t __be16 inner_eth_proto,\n+\t\t\t\t\t int inner_nhoff, int hlen, int num_hdrs);\n+static bool flow_dissect_fast_gre_inner(const struct sk_buff *skb,\n+\t\t\t\t\tstruct flow_dissector *flow_dissector,\n+\t\t\t\t\tvoid *target_container,\n+\t\t\t\t\tconst void *data,\n+\t\t\t\t\tint nhoff, int hlen, int num_hdrs);\n+\n+/* One of the two dissectors the fast-path eligibility check admits;\n+ * defined here so flow_dissect_fast() below can reference it (its keys\n+ * and init live near the bottom of the file).\n+ */\n+static struct flow_dissector flow_keys_dissector_symmetric __read_mostly;\n \n static void dissector_set_key(struct flow_dissector *flow_dissector,\n \t\t\t      enum flow_dissector_key_id key_id)\n@@ -73,6 +159,14 @@ void skb_flow_dissector_init(struct flow_dissector *flow_dissector,\n }\n EXPORT_SYMBOL(skb_flow_dissector_init);\n \n+/* Enabled while any netns has a BPF flow dissector program attached;\n+ * lets __skb_flow_dissect() skip the program lookup entirely in the\n+ * common no-program case. Maintained by the netns-BPF attach/detach\n+ * paths in kernel/bpf/net_namespace.c.\n+ */\n+DEFINE_STATIC_KEY_FALSE(netns_bpf_flow_dissector_enabled);\n+EXPORT_SYMBOL(netns_bpf_flow_dissector_enabled);\n+\n #ifdef CONFIG_BPF_SYSCALL\n int flow_dissector_bpf_prog_attach_check(struct net *net,\n \t\t\t\t\t struct bpf_prog *prog)\n@@ -1035,6 +1129,688 @@ static bool is_pppoe_ses_hdr_valid(const struct pppoe_hdr *hdr)\n \treturn hdr-\u003ever == 1 \u0026\u0026 hdr-\u003etype == 1 \u0026\u0026 hdr-\u003ecode == 0;\n }\n \n+/* The IPv4 fast-path assumes a 20-byte IPv4 header (IHL == 5). The\n+ * runtime IHL check below is the dynamic invariant; this static\n+ * assertion is the compile-time one, in the unlikely case struct\n+ * iphdr ever grows.\n+ */\n+static_assert(sizeof(struct iphdr) == 20);\n+\n+/* Straight-line eth + IPv4 (IHL=5, not fragmented) + TCP|UDP. Returns\n+ * true when @target_container has been filled byte-identically to the\n+ * slow path; false on any miss (caller falls back to the slow path).\n+ */\n+static bool flow_dissect_fast_ipv4(const struct sk_buff *skb,\n+\t\t\t\t   struct flow_dissector *flow_dissector,\n+\t\t\t\t   void *target_container,\n+\t\t\t\t   const void *data,\n+\t\t\t\t   int nhoff, int hlen, int num_hdrs)\n+{\n+\tstruct flow_dissector_key_control *key_control;\n+\tstruct flow_dissector_key_addrs *key_addrs;\n+\tstruct flow_dissector_key_basic *key_basic;\n+\tstruct flow_dissector_key_ports *key_ports;\n+\tconst struct iphdr *iph;\n+\tint thoff;\n+\n+\tif (unlikely(hlen - nhoff \u003c (int)sizeof(*iph) + 4))\n+\t\treturn false;\n+\n+\tiph = (const struct iphdr *)((const u8 *)data + nhoff);\n+\n+\tif (unlikely(*(const u8 *)iph != FLOW_DIS_IPV4_VIHL_NOOPT))\n+\t\treturn false;\n+\n+\tif (unlikely(iph-\u003efrag_off \u0026 htons(IP_MF | IP_OFFSET)))\n+\t\treturn false;\n+\n+\tif (unlikely(iph-\u003eprotocol != IPPROTO_TCP \u0026\u0026\n+\t\t     iph-\u003eprotocol != IPPROTO_UDP)) {\n+\t\t/* IPIP / IPv6-in-IPv4 outer: defer to the inner fast-path and\n+\t\t * stamp ENCAP. Outer addrs are not written -- the inner pass\n+\t\t * overwrites them, as in the slow path.\n+\t\t */\n+\t\tif (static_branch_unlikely(\u0026flow_dissector_ipip_key)) {\n+\t\t\tif (iph-\u003eprotocol == IPPROTO_IPIP)\n+\t\t\t\treturn flow_dissect_fast_ipip_inner(skb,\n+\t\t\t\t\t\tflow_dissector, target_container,\n+\t\t\t\t\t\tdata, htons(ETH_P_IP),\n+\t\t\t\t\t\tnhoff + (int)sizeof(*iph), hlen, num_hdrs);\n+\t\t\tif (iph-\u003eprotocol == IPPROTO_IPV6)\n+\t\t\t\treturn flow_dissect_fast_ipip_inner(skb,\n+\t\t\t\t\t\tflow_dissector, target_container,\n+\t\t\t\t\t\tdata, htons(ETH_P_IPV6),\n+\t\t\t\t\t\tnhoff + (int)sizeof(*iph), hlen, num_hdrs);\n+\t\t}\n+\t\tif (static_branch_unlikely(\u0026flow_dissector_gre_key) \u0026\u0026\n+\t\t    iph-\u003eprotocol == IPPROTO_GRE)\n+\t\t\treturn flow_dissect_fast_gre_inner(skb, flow_dissector,\n+\t\t\t\t\ttarget_container, data,\n+\t\t\t\t\tnhoff + (int)sizeof(*iph), hlen, num_hdrs);\n+\t\treturn false;\n+\t}\n+\n+\tthoff = nhoff + (int)sizeof(*iph);\n+\n+\tif (dissector_uses_key(flow_dissector,\n+\t\t\t       FLOW_DISSECTOR_KEY_CONTROL)) {\n+\t\tkey_control = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t\tFLOW_DISSECTOR_KEY_CONTROL,\n+\t\t\t\t\t\t\ttarget_container);\n+\t\tkey_control-\u003eaddr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;\n+\t\tkey_control-\u003ethoff = min_t(u16, thoff,\n+\t\t\t\t\t   skb ? skb-\u003elen : hlen);\n+\t\tkey_control-\u003eflags = 0;\n+\t}\n+\tif (dissector_uses_key(flow_dissector,\n+\t\t\t       FLOW_DISSECTOR_KEY_BASIC)) {\n+\t\tkey_basic = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t      FLOW_DISSECTOR_KEY_BASIC,\n+\t\t\t\t\t\t      target_container);\n+\t\tkey_basic-\u003en_proto = htons(ETH_P_IP);\n+\t\tkey_basic-\u003eip_proto = iph-\u003eprotocol;\n+\t}\n+\tif (dissector_uses_key(flow_dissector,\n+\t\t\t       FLOW_DISSECTOR_KEY_IPV4_ADDRS)) {\n+\t\tkey_addrs = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t      FLOW_DISSECTOR_KEY_IPV4_ADDRS,\n+\t\t\t\t\t\t      target_container);\n+\t\tmemcpy(\u0026key_addrs-\u003ev4addrs.src, \u0026iph-\u003esaddr,\n+\t\t       sizeof(key_addrs-\u003ev4addrs.src));\n+\t\tmemcpy(\u0026key_addrs-\u003ev4addrs.dst, \u0026iph-\u003edaddr,\n+\t\t       sizeof(key_addrs-\u003ev4addrs.dst));\n+\t}\n+\tif (dissector_uses_key(flow_dissector,\n+\t\t\t       FLOW_DISSECTOR_KEY_PORTS)) {\n+\t\tconst __be32 *ports = (const __be32 *)\n+\t\t\t((const u8 *)data + thoff);\n+\n+\t\tkey_ports = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t      FLOW_DISSECTOR_KEY_PORTS,\n+\t\t\t\t\t\t      target_container);\n+\t\tkey_ports-\u003eports = *ports;\n+\t}\n+\n+\treturn true;\n+}\n+\n+/* Same as flow_dissect_fast_ipv4 but for a fixed 40-byte IPv6 header\n+ * (no extension headers). The nexthdr check below holds the run-time\n+ * invariant; the static_assert holds the compile-time one.\n+ */\n+static_assert(sizeof(struct ipv6hdr) == 40);\n+\n+static bool flow_dissect_fast_ipv6(const struct sk_buff *skb,\n+\t\t\t\t   struct flow_dissector *flow_dissector,\n+\t\t\t\t   void *target_container,\n+\t\t\t\t   const void *data,\n+\t\t\t\t   int nhoff, int hlen, int num_hdrs)\n+{\n+\tstruct flow_dissector_key_control *key_control;\n+\tstruct flow_dissector_key_addrs *key_addrs;\n+\tstruct flow_dissector_key_basic *key_basic;\n+\tstruct flow_dissector_key_ports *key_ports;\n+\tconst struct ipv6hdr *iph;\n+\tint thoff;\n+\n+\tif (unlikely(hlen - nhoff \u003c (int)sizeof(*iph) + 4))\n+\t\treturn false;\n+\n+\tiph = (const struct ipv6hdr *)((const u8 *)data + nhoff);\n+\n+\tif (unlikely((*(const u8 *)iph \u003e\u003e 4) != 6))\n+\t\treturn false;\n+\n+\t/* Any non-zero flow label defers, checked before everything else\n+\t * (including the tunnel descents below). Callers passing\n+\t * FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL (skb_get_hash() -- so\n+\t * RPS/RFS, fq, cake) make the slow path stop at a non-zero label\n+\t * even on a tunnel outer, and dissectors requesting the label key\n+\t * write it; both diverge from the plain parse. Deferring on the\n+\t * label itself covers every combination without threading flags\n+\t * into the helpers, and zero-label IPv6 (the overwhelmingly\n+\t * common case) stays on the fast path.\n+\t */\n+\tif (unlikely((iph-\u003eflow_lbl[0] \u0026 0x0f) |\n+\t\t     iph-\u003eflow_lbl[1] | iph-\u003eflow_lbl[2]))\n+\t\treturn false;\n+\n+\tif (unlikely(iph-\u003enexthdr != IPPROTO_TCP \u0026\u0026\n+\t\t     iph-\u003enexthdr != IPPROTO_UDP)) {\n+\t\t/* IPIP / IPV6-in-IPv6 tunnel outer: same pattern as the\n+\t\t * IPv4 helper. The nexthdr_IPIP / nexthdr_IPV6 cases\n+\t\t * defer to the inner IP fast-path and stamp ENCAP.\n+\t\t */\n+\t\tbool ipip = static_branch_unlikely(\u0026flow_dissector_ipip_key) \u0026\u0026\n+\t\t\t    (iph-\u003enexthdr == IPPROTO_IPIP ||\n+\t\t\t     iph-\u003enexthdr == IPPROTO_IPV6);\n+\t\tbool gre = static_branch_unlikely(\u0026flow_dissector_gre_key) \u0026\u0026\n+\t\t\t   iph-\u003enexthdr == IPPROTO_GRE;\n+\n+\t\tif (!ipip \u0026\u0026 !gre)\n+\t\t\treturn false;\n+\n+\t\t/* Mirror the slow path's outer-IPv6 writes before the\n+\t\t * descent. The slow path fills v6addrs for the outer\n+\t\t * header and the inner pass then overwrites only what\n+\t\t * it uses — an inner IPv4 leaves the tail of the addrs\n+\t\t * union holding outer-v6 bytes. Byte-identical means\n+\t\t * reproducing exactly that, residue included. (The\n+\t\t * outer flow label is always zero here — a non-zero\n+\t\t * label deferred above — so there is no label residue.)\n+\t\t */\n+\t\tif (dissector_uses_key(flow_dissector,\n+\t\t\t\t       FLOW_DISSECTOR_KEY_IPV6_ADDRS)) {\n+\t\t\tkey_addrs = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t\t      FLOW_DISSECTOR_KEY_IPV6_ADDRS,\n+\t\t\t\t\t\t\t      target_container);\n+\t\t\tmemcpy(\u0026key_addrs-\u003ev6addrs.src, \u0026iph-\u003esaddr,\n+\t\t\t       sizeof(key_addrs-\u003ev6addrs.src));\n+\t\t\tmemcpy(\u0026key_addrs-\u003ev6addrs.dst, \u0026iph-\u003edaddr,\n+\t\t\t       sizeof(key_addrs-\u003ev6addrs.dst));\n+\t\t\tkey_control = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t\t\tFLOW_DISSECTOR_KEY_CONTROL,\n+\t\t\t\t\t\t\t\ttarget_container);\n+\t\t\tkey_control-\u003eaddr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;\n+\t\t}\n+\n+\t\tif (ipip)\n+\t\t\treturn flow_dissect_fast_ipip_inner(skb,\n+\t\t\t\t\tflow_dissector, target_container,\n+\t\t\t\t\tdata,\n+\t\t\t\t\tiph-\u003enexthdr == IPPROTO_IPIP ?\n+\t\t\t\t\thtons(ETH_P_IP) : htons(ETH_P_IPV6),\n+\t\t\t\t\tnhoff + (int)sizeof(*iph), hlen, num_hdrs);\n+\t\treturn flow_dissect_fast_gre_inner(skb, flow_dissector,\n+\t\t\t\ttarget_container, data,\n+\t\t\t\tnhoff + (int)sizeof(*iph), hlen, num_hdrs);\n+\t}\n+\n+\tthoff = nhoff + (int)sizeof(*iph);\n+\n+\tif (dissector_uses_key(flow_dissector,\n+\t\t\t       FLOW_DISSECTOR_KEY_CONTROL)) {\n+\t\tkey_control = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t\tFLOW_DISSECTOR_KEY_CONTROL,\n+\t\t\t\t\t\t\ttarget_container);\n+\t\tkey_control-\u003eaddr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;\n+\t\tkey_control-\u003ethoff = min_t(u16, thoff,\n+\t\t\t\t\t   skb ? skb-\u003elen : hlen);\n+\t\tkey_control-\u003eflags = 0;\n+\t}\n+\tif (dissector_uses_key(flow_dissector,\n+\t\t\t       FLOW_DISSECTOR_KEY_BASIC)) {\n+\t\tkey_basic = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t      FLOW_DISSECTOR_KEY_BASIC,\n+\t\t\t\t\t\t      target_container);\n+\t\tkey_basic-\u003en_proto = htons(ETH_P_IPV6);\n+\t\tkey_basic-\u003eip_proto = iph-\u003enexthdr;\n+\t}\n+\tif (dissector_uses_key(flow_dissector,\n+\t\t\t       FLOW_DISSECTOR_KEY_IPV6_ADDRS)) {\n+\t\tkey_addrs = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t      FLOW_DISSECTOR_KEY_IPV6_ADDRS,\n+\t\t\t\t\t\t      target_container);\n+\t\tmemcpy(\u0026key_addrs-\u003ev6addrs.src, \u0026iph-\u003esaddr,\n+\t\t       sizeof(key_addrs-\u003ev6addrs.src));\n+\t\tmemcpy(\u0026key_addrs-\u003ev6addrs.dst, \u0026iph-\u003edaddr,\n+\t\t       sizeof(key_addrs-\u003ev6addrs.dst));\n+\t}\n+\tif (dissector_uses_key(flow_dissector,\n+\t\t\t       FLOW_DISSECTOR_KEY_PORTS)) {\n+\t\tconst __be32 *ports = (const __be32 *)\n+\t\t\t((const u8 *)data + thoff);\n+\n+\t\tkey_ports = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t      FLOW_DISSECTOR_KEY_PORTS,\n+\t\t\t\t\t\t      target_container);\n+\t\tkey_ports-\u003eports = *ports;\n+\t}\n+\n+\treturn true;\n+}\n+\n+/* Strip up to two 802.1Q/802.1AD tags: outer tag -\u003e\n+ * FLOW_DISSECTOR_KEY_VLAN, inner -\u003e _CVLAN, mirroring the slow path's\n+ * MAX -\u003e VLAN -\u003e CVLAN state machine; more than two tags defer.\n+ * Depth 0 is gated by the vlan key, depth \u003e= 1 by the qinq key (the\n+ * qinq sysctl also flips vlan on -- see the proc_handlers).\n+ */\n+static bool flow_dissect_fast_vlan(const struct sk_buff *skb,\n+\t\t\t\t   struct flow_dissector *flow_dissector,\n+\t\t\t\t   void *target_container,\n+\t\t\t\t   const void *data,\n+\t\t\t\t   __be16 proto, int nhoff, int hlen,\n+\t\t\t\t   int vlan_depth)\n+{\n+\tstruct flow_dissector_key_num_of_vlans *key_nvs;\n+\tstruct flow_dissector_key_vlan *key_vlan;\n+\tenum flow_dissector_key_id vlan_key;\n+\t__be16 inner_proto;\n+\t__be16 saved_tpid;\n+\tu16 tci_prio;\n+\tu16 tci_id;\n+\tbool ok;\n+\n+\tif (vlan_depth \u003e= 1 \u0026\u0026\n+\t    !static_branch_unlikely(\u0026flow_dissector_qinq_key))\n+\t\treturn false;\n+\tif (vlan_depth \u003e= 2)\n+\t\treturn false;\n+\n+\tvlan_key = vlan_depth == 0 ?\n+\t\t   FLOW_DISSECTOR_KEY_VLAN :\n+\t\t   FLOW_DISSECTOR_KEY_CVLAN;\n+\tsaved_tpid = proto;\n+\n+\t/* HW-stripped tag is only ever the outermost. */\n+\tif (vlan_depth == 0 \u0026\u0026 skb \u0026\u0026 skb_vlan_tag_present(skb)) {\n+\t\ttci_id = skb_vlan_tag_get_id(skb);\n+\t\ttci_prio = skb_vlan_tag_get_prio(skb);\n+\t\tinner_proto = skb-\u003eprotocol;\n+\t} else {\n+\t\tconst struct vlan_hdr *vlan;\n+\n+\t\tif (unlikely(hlen - nhoff \u003c (int)sizeof(*vlan)))\n+\t\t\treturn false;\n+\t\tvlan = (const struct vlan_hdr *)((const u8 *)data + nhoff);\n+\t\ttci_id = ntohs(vlan-\u003eh_vlan_TCI) \u0026 VLAN_VID_MASK;\n+\t\ttci_prio = (ntohs(vlan-\u003eh_vlan_TCI) \u0026\n+\t\t\t    VLAN_PRIO_MASK) \u003e\u003e VLAN_PRIO_SHIFT;\n+\t\tinner_proto = vlan-\u003eh_vlan_encapsulated_proto;\n+\t\tnhoff += (int)sizeof(*vlan);\n+\t}\n+\n+\tif (dissector_uses_key(flow_dissector, vlan_key)) {\n+\t\tkey_vlan = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t     vlan_key,\n+\t\t\t\t\t\t     target_container);\n+\t\tkey_vlan-\u003evlan_id = tci_id;\n+\t\tkey_vlan-\u003evlan_priority = tci_prio;\n+\t\tkey_vlan-\u003evlan_tpid = saved_tpid;\n+\t\tkey_vlan-\u003evlan_eth_type = inner_proto;\n+\t}\n+\tif (dissector_uses_key(flow_dissector,\n+\t\t\t       FLOW_DISSECTOR_KEY_NUM_OF_VLANS)) {\n+\t\tkey_nvs = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t    FLOW_DISSECTOR_KEY_NUM_OF_VLANS,\n+\t\t\t\t\t\t    target_container);\n+\t\tkey_nvs-\u003enum_of_vlans++;\n+\t}\n+\n+\tswitch (inner_proto) {\n+\tcase htons(ETH_P_IP):\n+\t\tok = flow_dissect_fast_ipv4(skb, flow_dissector,\n+\t\t\t\t\t    target_container, data,\n+\t\t\t\t\t    nhoff, hlen, vlan_depth + 2);\n+\t\tbreak;\n+\tcase htons(ETH_P_IPV6):\n+\t\tok = flow_dissect_fast_ipv6(skb, flow_dissector,\n+\t\t\t\t\t    target_container, data,\n+\t\t\t\t\t    nhoff, hlen, vlan_depth + 2);\n+\t\tbreak;\n+\tcase htons(ETH_P_8021Q):\n+\tcase htons(ETH_P_8021AD):\n+\t\tok = flow_dissect_fast_vlan(skb, flow_dissector,\n+\t\t\t\t\t    target_container, data,\n+\t\t\t\t\t    inner_proto, nhoff, hlen,\n+\t\t\t\t\t    vlan_depth + 1);\n+\t\tbreak;\n+\tdefault:\n+\t\treturn false;\n+\t}\n+\n+\t/* Count only on full success -- a miss defers and the slow path\n+\t * counts the occurrence. Depth 0 counts vlan, depth \u003e= 1 qinq; a\n+\t * double-tagged hit counts both, as the slow path does.\n+\t */\n+\tif (ok)\n+\t\tflow_dissector_count_fast(vlan_depth == 0 ?\n+\t\t\t\t\t  FLOW_DISSECTOR_SHAPE_VLAN :\n+\t\t\t\t\t  FLOW_DISSECTOR_SHAPE_QINQ);\n+\treturn ok;\n+}\n+\n+/* PPPoE session (RFC 2516) + 2-byte PPP protocol: write\n+ * FLOW_DISSECTOR_KEY_PPPOE if requested, then tail-call the eth_ip\n+ * fast-path for PPP_IP / PPP_IPV6. Anything else (PFC-compressed\n+ * protocol, LCP, MPLS) defers.\n+ */\n+static bool flow_dissect_fast_pppoe(const struct sk_buff *skb,\n+\t\t\t\t    struct flow_dissector *flow_dissector,\n+\t\t\t\t    void *target_container,\n+\t\t\t\t    const void *data,\n+\t\t\t\t    int nhoff, int hlen)\n+{\n+\tstruct flow_dissector_key_pppoe *key_pppoe;\n+\tconst struct {\n+\t\tstruct pppoe_hdr hdr;\n+\t\t__be16 proto;\n+\t} *hdr;\n+\t__be16 inner_eth_proto;\n+\tu16 ppp_proto;\n+\tbool ok;\n+\n+\tif (unlikely(hlen - nhoff \u003c (int)sizeof(*hdr)))\n+\t\treturn false;\n+\thdr = (const void *)((const u8 *)data + nhoff);\n+\tif (!is_pppoe_ses_hdr_valid(\u0026hdr-\u003ehdr))\n+\t\treturn false;\n+\n+\tppp_proto = ntohs(hdr-\u003eproto);\n+\tswitch (ppp_proto) {\n+\tcase PPP_IP:\n+\t\tinner_eth_proto = htons(ETH_P_IP);\n+\t\tbreak;\n+\tcase PPP_IPV6:\n+\t\tinner_eth_proto = htons(ETH_P_IPV6);\n+\t\tbreak;\n+\tdefault:\n+\t\t/* MPLS unicast/multicast + everything else (LCP, IPCP,\n+\t\t * compressed PFC, ...) defers to the slow path.\n+\t\t */\n+\t\treturn false;\n+\t}\n+\n+\tif (dissector_uses_key(flow_dissector,\n+\t\t\t       FLOW_DISSECTOR_KEY_PPPOE)) {\n+\t\tkey_pppoe = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t      FLOW_DISSECTOR_KEY_PPPOE,\n+\t\t\t\t\t\t      target_container);\n+\t\tkey_pppoe-\u003esession_id = hdr-\u003ehdr.sid;\n+\t\tkey_pppoe-\u003eppp_proto = htons(ppp_proto);\n+\t\tkey_pppoe-\u003etype = htons(ETH_P_PPP_SES);\n+\t}\n+\n+\tnhoff += PPPOE_SES_HLEN;\n+\n+\tif (inner_eth_proto == htons(ETH_P_IP))\n+\t\tok = flow_dissect_fast_ipv4(skb, flow_dissector,\n+\t\t\t\t\t    target_container, data,\n+\t\t\t\t\t    nhoff, hlen, 2);\n+\telse\n+\t\tok = flow_dissect_fast_ipv6(skb, flow_dissector,\n+\t\t\t\t\t    target_container, data,\n+\t\t\t\t\t    nhoff, hlen, 2);\n+\n+\tif (ok)\n+\t\tflow_dissector_count_fast(FLOW_DISSECTOR_SHAPE_PPPOE);\n+\treturn ok;\n+}\n+\n+/* Single MPLS label (BoS=1): write FLOW_DISSECTOR_KEY_MPLS lse[0]\n+ * when requested and stop -- the slow path returns OUT_GOOD on BoS\n+ * without descending into the inner packet, so the fast path must\n+ * not tail-call either. Multi-label stacks defer.\n+ */\n+static bool flow_dissect_fast_mpls(const struct sk_buff *skb,\n+\t\t\t\t   struct flow_dissector *flow_dissector,\n+\t\t\t\t   void *target_container,\n+\t\t\t\t   const void *data,\n+\t\t\t\t   __be16 proto, int nhoff, int hlen)\n+{\n+\tstruct flow_dissector_key_control *key_control;\n+\tstruct flow_dissector_key_basic *key_basic;\n+\tstruct flow_dissector_key_mpls *key_mpls;\n+\tstruct flow_dissector_mpls_lse *lse;\n+\tconst struct mpls_label *hdr;\n+\tu32 entry, label, bos;\n+\n+\tif (unlikely(hlen - nhoff \u003c (int)sizeof(*hdr)))\n+\t\treturn false;\n+\thdr = (const struct mpls_label *)((const u8 *)data + nhoff);\n+\tentry = ntohl(hdr-\u003eentry);\n+\tbos = (entry \u0026 MPLS_LS_S_MASK) \u003e\u003e MPLS_LS_S_SHIFT;\n+\n+\t/* Multi-label stack: defer. */\n+\tif (!bos)\n+\t\treturn false;\n+\n+\t/* Neither MPLS key requested: the slow path returns OUT_GOOD without\n+\t * writing the key; skipping the write block matches it.\n+\t */\n+\tlabel = (entry \u0026 MPLS_LS_LABEL_MASK) \u003e\u003e MPLS_LS_LABEL_SHIFT;\n+\n+\tif (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_MPLS)) {\n+\t\tkey_mpls = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t     FLOW_DISSECTOR_KEY_MPLS,\n+\t\t\t\t\t\t     target_container);\n+\t\tlse = \u0026key_mpls-\u003els[0];\n+\t\tlse-\u003empls_ttl = (entry \u0026 MPLS_LS_TTL_MASK) \u003e\u003e MPLS_LS_TTL_SHIFT;\n+\t\tlse-\u003empls_bos = bos;\n+\t\tlse-\u003empls_tc = (entry \u0026 MPLS_LS_TC_MASK) \u003e\u003e MPLS_LS_TC_SHIFT;\n+\t\tlse-\u003empls_label = label;\n+\t\tdissector_set_mpls_lse(key_mpls, 0);\n+\t}\n+\n+\t/* Mirror the slow path's out_good terminal: nhoff advances past the\n+\t * LSE, then thoff/basic are written from the final proto/ip_proto.\n+\t */\n+\tnhoff += (int)sizeof(*hdr);\n+\tif (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_CONTROL)) {\n+\t\tkey_control = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t\tFLOW_DISSECTOR_KEY_CONTROL,\n+\t\t\t\t\t\t\ttarget_container);\n+\t\tkey_control-\u003ethoff = min_t(u16, nhoff,\n+\t\t\t\t\t   skb ? skb-\u003elen : hlen);\n+\t}\n+\tif (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_BASIC)) {\n+\t\tkey_basic = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t      FLOW_DISSECTOR_KEY_BASIC,\n+\t\t\t\t\t\t      target_container);\n+\t\tkey_basic-\u003en_proto = proto;\n+\t\tkey_basic-\u003eip_proto = 0;\n+\t}\n+\n+\tflow_dissector_count_fast(FLOW_DISSECTOR_SHAPE_MPLS);\n+\treturn true;\n+}\n+\n+/* IPIP / 4in6 / 6in4 inner descent: recurse into the inner IP\n+ * fast-path, then stamp FLOW_DIS_ENCAPSULATION -- the inner helper\n+ * zeros key_control-\u003eflags, so the ENCAP write must come after.\n+ */\n+static bool flow_dissect_fast_ipip_inner(const struct sk_buff *skb,\n+\t\t\t\t\t struct flow_dissector *flow_dissector,\n+\t\t\t\t\t void *target_container,\n+\t\t\t\t\t const void *data,\n+\t\t\t\t\t __be16 inner_eth_proto,\n+\t\t\t\t\t int inner_nhoff, int hlen, int num_hdrs)\n+{\n+\tstruct flow_dissector_key_control *key_control;\n+\tbool ok;\n+\n+\t/* Mirror the slow path's MAX_FLOW_DISSECT_HDRS budget; past the cap\n+\t * defer, so both paths stop at the same depth.\n+\t */\n+\tif (++num_hdrs \u003e MAX_FLOW_DISSECT_HDRS)\n+\t\treturn false;\n+\n+\tif (inner_eth_proto == htons(ETH_P_IP))\n+\t\tok = flow_dissect_fast_ipv4(skb, flow_dissector,\n+\t\t\t\t\t    target_container, data,\n+\t\t\t\t\t    inner_nhoff, hlen, num_hdrs);\n+\telse if (inner_eth_proto == htons(ETH_P_IPV6))\n+\t\tok = flow_dissect_fast_ipv6(skb, flow_dissector,\n+\t\t\t\t\t    target_container, data,\n+\t\t\t\t\t    inner_nhoff, hlen, num_hdrs);\n+\telse\n+\t\treturn false;\n+\n+\tif (!ok)\n+\t\treturn false;\n+\n+\tif (dissector_uses_key(flow_dissector,\n+\t\t\t       FLOW_DISSECTOR_KEY_CONTROL)) {\n+\t\tkey_control = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t\tFLOW_DISSECTOR_KEY_CONTROL,\n+\t\t\t\t\t\t\ttarget_container);\n+\t\tkey_control-\u003eflags |= FLOW_DIS_ENCAPSULATION;\n+\t}\n+\tflow_dissector_count_fast(FLOW_DISSECTOR_SHAPE_IPIP);\n+\treturn true;\n+}\n+\n+/* Plain-GRE inner descent (version 0, no flags, inner IP): a 4-byte\n+ * base header the slow path steps over with PROTO_AGAIN. Any flags,\n+ * version 1 (PPTP) or a non-IP inner defers. ENCAP is stamped after\n+ * the inner pass, which zeros key_control-\u003eflags.\n+ */\n+static bool flow_dissect_fast_gre_inner(const struct sk_buff *skb,\n+\t\t\t\t\tstruct flow_dissector *flow_dissector,\n+\t\t\t\t\tvoid *target_container,\n+\t\t\t\t\tconst void *data,\n+\t\t\t\t\tint nhoff, int hlen, int num_hdrs)\n+{\n+\tstruct flow_dissector_key_control *key_control;\n+\tconst struct gre_base_hdr *hdr;\n+\t__be16 inner_proto;\n+\tint inner_nhoff;\n+\tbool ok;\n+\n+\t/* Same MAX_FLOW_DISSECT_HDRS budget as flow_dissect_fast_ipip_inner(). */\n+\tif (++num_hdrs \u003e MAX_FLOW_DISSECT_HDRS)\n+\t\treturn false;\n+\n+\tif (unlikely(hlen - nhoff \u003c (int)sizeof(*hdr)))\n+\t\treturn false;\n+\thdr = (const struct gre_base_hdr *)((const u8 *)data + nhoff);\n+\n+\t/* flags field carries the GRE control flags *and* the 3-bit\n+\t * version in its low bits. A zero word means \"no flags set\n+\t * AND version 0\" — the byte-identical fast subset.\n+\t */\n+\tif (hdr-\u003eflags != 0)\n+\t\treturn false;\n+\n+\tswitch (hdr-\u003eprotocol) {\n+\tcase htons(ETH_P_IP):\n+\t\tinner_proto = htons(ETH_P_IP);\n+\t\tbreak;\n+\tcase htons(ETH_P_IPV6):\n+\t\tinner_proto = htons(ETH_P_IPV6);\n+\t\tbreak;\n+\tdefault:\n+\t\treturn false;\n+\t}\n+\n+\tinner_nhoff = nhoff + (int)sizeof(*hdr);\n+\n+\tif (inner_proto == htons(ETH_P_IP))\n+\t\tok = flow_dissect_fast_ipv4(skb, flow_dissector,\n+\t\t\t\t\t    target_container, data,\n+\t\t\t\t\t    inner_nhoff, hlen, num_hdrs);\n+\telse\n+\t\tok = flow_dissect_fast_ipv6(skb, flow_dissector,\n+\t\t\t\t\t    target_container, data,\n+\t\t\t\t\t    inner_nhoff, hlen, num_hdrs);\n+\n+\tif (!ok)\n+\t\treturn false;\n+\n+\t/* Re-establish ENCAP after the inner pass zeroed key_control-\u003eflags. */\n+\tif (dissector_uses_key(flow_dissector,\n+\t\t\t       FLOW_DISSECTOR_KEY_CONTROL)) {\n+\t\tkey_control = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\t\tFLOW_DISSECTOR_KEY_CONTROL,\n+\t\t\t\t\t\t\ttarget_container);\n+\t\tkey_control-\u003eflags |= FLOW_DIS_ENCAPSULATION;\n+\t}\n+\tflow_dissector_count_fast(FLOW_DISSECTOR_SHAPE_GRE);\n+\treturn true;\n+}\n+\n+/* Did a fast-path leaf stamp FLOW_DIS_ENCAPSULATION? The dispatcher\n+ * counts eth_ip only for plain top-level IP; descents count under\n+ * their own shape (UDP-tunnel descents not at all).\n+ */\n+static bool flow_dissect_fast_is_encap(struct flow_dissector *flow_dissector,\n+\t\t\t\t       void *target_container)\n+{\n+\tstruct flow_dissector_key_control *key_control;\n+\n+\tif (!dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_CONTROL))\n+\t\treturn false;\n+\tkey_control = skb_flow_dissector_target(flow_dissector,\n+\t\t\t\t\t\tFLOW_DISSECTOR_KEY_CONTROL,\n+\t\t\t\t\t\ttarget_container);\n+\treturn key_control-\u003eflags \u0026 FLOW_DIS_ENCAPSULATION;\n+}\n+\n+/* Top-level dispatcher: eligibility check (only the two standard\n+ * dissectors and flag subset) + per-proto switch with per-shape\n+ * static_branch gating. Each case's branch is a forward not-taken JMP\n+ * when its sysctl is 0 — matches the slow-path cost.\n+ */\n+static bool flow_dissect_fast(const struct sk_buff *skb,\n+\t\t\t      struct flow_dissector *flow_dissector,\n+\t\t\t      void *target_container,\n+\t\t\t      const void *data,\n+\t\t\t      __be16 proto, int nhoff, int hlen,\n+\t\t\t      unsigned int flags)\n+{\n+\tif (flow_dissector != \u0026flow_keys_dissector \u0026\u0026\n+\t    flow_dissector != \u0026flow_keys_dissector_symmetric)\n+\t\treturn false;\n+\n+\t/* skb_get_hash() -- behind RPS/RFS, fq, fq_codel, cake -- passes\n+\t * FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL on every dissect, so the\n+\t * flag must be admitted or the fast path never runs for the\n+\t * kernel's main consumers. Its only semantic (stop early on a\n+\t * non-zero IPv6 flow label) is subsumed by the IPv6 fast path\n+\t * deferring on any non-zero label. Any other flag defers.\n+\t */\n+\tif (flags \u0026 ~(unsigned int)(FLOW_DISSECTOR_F_PARSE_1ST_FRAG |\n+\t\t\t\t    FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL))\n+\t\treturn false;\n+\n+\tswitch (proto) {\n+\tcase htons(ETH_P_8021Q):\n+\tcase htons(ETH_P_8021AD):\n+\t\tif (!static_branch_unlikely(\u0026flow_dissector_vlan_key))\n+\t\t\treturn false;\n+\t\treturn flow_dissect_fast_vlan(skb, flow_dissector,\n+\t\t\t\t\t      target_container, data,\n+\t\t\t\t\t      proto, nhoff, hlen, 0);\n+\tcase htons(ETH_P_IP):\n+\t\tif (!static_branch_unlikely(\u0026flow_dissector_eth_ip_key))\n+\t\t\treturn false;\n+\t\tif (!flow_dissect_fast_ipv4(skb, flow_dissector,\n+\t\t\t\t\t    target_container, data,\n+\t\t\t\t\t    nhoff, hlen, 1))\n+\t\t\treturn false;\n+\t\t/* Plain top-level eth+IP only; descents count under their own shape. */\n+\t\tif (!flow_dissect_fast_is_encap(flow_dissector, target_container))\n+\t\t\tflow_dissector_count_fast(FLOW_DISSECTOR_SHAPE_ETH_IP);\n+\t\treturn true;\n+\tcase htons(ETH_P_IPV6):\n+\t\tif (!static_branch_unlikely(\u0026flow_dissector_eth_ip_key))\n+\t\t\treturn false;\n+\t\tif (!flow_dissect_fast_ipv6(skb, flow_dissector,\n+\t\t\t\t\t    target_container, data,\n+\t\t\t\t\t    nhoff, hlen, 1))\n+\t\t\treturn false;\n+\t\tif (!flow_dissect_fast_is_encap(flow_dissector, target_container))\n+\t\t\tflow_dissector_count_fast(FLOW_DISSECTOR_SHAPE_ETH_IP);\n+\t\treturn true;\n+\tcase htons(ETH_P_PPP_SES):\n+\t\tif (!static_branch_unlikely(\u0026flow_dissector_pppoe_key))\n+\t\t\treturn false;\n+\t\treturn flow_dissect_fast_pppoe(skb, flow_dissector,\n+\t\t\t\t\t       target_container, data,\n+\t\t\t\t\t       nhoff, hlen);\n+\tcase htons(ETH_P_MPLS_UC):\n+\tcase htons(ETH_P_MPLS_MC):\n+\t\tif (!static_branch_unlikely(\u0026flow_dissector_mpls_key))\n+\t\t\treturn false;\n+\t\treturn flow_dissect_fast_mpls(skb, flow_dissector,\n+\t\t\t\t\t      target_container, data,\n+\t\t\t\t\t      proto, nhoff, hlen);\n+\tdefault:\n+\t\treturn false;\n+\t}\n+}\n+\n /**\n  * __skb_flow_dissect - extract the flow_keys struct and return it\n  * @net: associated network namespace, derived from @skb if NULL\n@@ -1070,6 +1846,8 @@ bool __skb_flow_dissect(const struct net *net,\n \tbool mpls_el = false;\n \tint mpls_lse = 0;\n \tint num_hdrs = 0;\n+\tint nhoff_init = 0;\n+\tbool eth_ip_top = false;\n \tu8 ip_proto = 0;\n \tbool ret;\n \n@@ -1117,59 +1895,72 @@ bool __skb_flow_dissect(const struct net *net,\n \t\t\t\t\t      FLOW_DISSECTOR_KEY_BASIC,\n \t\t\t\t\t      target_container);\n \n-\trcu_read_lock();\n+\tif (static_branch_unlikely(\u0026netns_bpf_flow_dissector_enabled)) {\n+\t\trcu_read_lock();\n \n-\tif (skb) {\n-\t\tif (!net) {\n-\t\t\tif (skb-\u003edev)\n-\t\t\t\tnet = dev_net_rcu(skb-\u003edev);\n-\t\t\telse if (skb-\u003esk)\n-\t\t\t\tnet = sock_net(skb-\u003esk);\n+\t\tif (skb) {\n+\t\t\tif (!net) {\n+\t\t\t\tif (skb-\u003edev)\n+\t\t\t\t\tnet = dev_net_rcu(skb-\u003edev);\n+\t\t\t\telse if (skb-\u003esk)\n+\t\t\t\t\tnet = sock_net(skb-\u003esk);\n+\t\t\t}\n \t\t}\n-\t}\n \n-\tDEBUG_NET_WARN_ON_ONCE(!net);\n-\tif (net) {\n-\t\tenum netns_bpf_attach_type type = NETNS_BPF_FLOW_DISSECTOR;\n-\t\tstruct bpf_prog_array *run_array;\n-\n-\t\trun_array = rcu_dereference(init_net.bpf.run_array[type]);\n-\t\tif (!run_array)\n-\t\t\trun_array = rcu_dereference(net-\u003ebpf.run_array[type]);\n-\n-\t\tif (run_array) {\n-\t\t\tstruct bpf_flow_keys flow_keys;\n-\t\t\tstruct bpf_flow_dissector ctx = {\n-\t\t\t\t.flow_keys = \u0026flow_keys,\n-\t\t\t\t.data = data,\n-\t\t\t\t.data_end = data + hlen,\n-\t\t\t};\n-\t\t\t__be16 n_proto = proto;\n-\t\t\tstruct bpf_prog *prog;\n-\t\t\tu32 result;\n-\n-\t\t\tif (skb) {\n-\t\t\t\tctx.skb = skb;\n-\t\t\t\t/* we can't use 'proto' in the skb case\n-\t\t\t\t * because it might be set to skb-\u003evlan_proto\n-\t\t\t\t * which has been pulled from the data\n-\t\t\t\t */\n-\t\t\t\tn_proto = skb-\u003eprotocol;\n-\t\t\t}\n+\t\tDEBUG_NET_WARN_ON_ONCE(!net);\n+\t\tif (net) {\n+\t\t\tenum netns_bpf_attach_type type = NETNS_BPF_FLOW_DISSECTOR;\n+\t\t\tstruct bpf_prog_array *run_array;\n+\n+\t\t\trun_array = rcu_dereference(init_net.bpf.run_array[type]);\n+\t\t\tif (!run_array)\n+\t\t\t\trun_array = rcu_dereference(net-\u003ebpf.run_array[type]);\n+\n+\t\t\tif (run_array) {\n+\t\t\t\tstruct bpf_flow_keys flow_keys;\n+\t\t\t\tstruct bpf_flow_dissector ctx = {\n+\t\t\t\t\t.flow_keys = \u0026flow_keys,\n+\t\t\t\t\t.data = data,\n+\t\t\t\t\t.data_end = data + hlen,\n+\t\t\t\t};\n+\t\t\t\t__be16 n_proto = proto;\n+\t\t\t\tstruct bpf_prog *prog;\n+\t\t\t\tu32 result;\n+\n+\t\t\t\tif (skb) {\n+\t\t\t\t\tctx.skb = skb;\n+\t\t\t\t\t/* we can't use 'proto' in the skb case\n+\t\t\t\t\t * because it might be set to\n+\t\t\t\t\t * skb-\u003evlan_proto which has been pulled\n+\t\t\t\t\t * from the data\n+\t\t\t\t\t */\n+\t\t\t\t\tn_proto = skb-\u003eprotocol;\n+\t\t\t\t}\n \n-\t\t\tprog = READ_ONCE(run_array-\u003eitems[0].prog);\n-\t\t\tresult = bpf_flow_dissect(prog, \u0026ctx, n_proto, nhoff,\n-\t\t\t\t\t\t  hlen, flags);\n-\t\t\tif (result != BPF_FLOW_DISSECTOR_CONTINUE) {\n-\t\t\t\t__skb_flow_bpf_to_target(\u0026flow_keys, flow_dissector,\n-\t\t\t\t\t\t\t target_container);\n-\t\t\t\trcu_read_unlock();\n-\t\t\t\treturn result == BPF_OK;\n+\t\t\t\tprog = READ_ONCE(run_array-\u003eitems[0].prog);\n+\t\t\t\tresult = bpf_flow_dissect(prog, \u0026ctx, n_proto,\n+\t\t\t\t\t\t\t  nhoff, hlen, flags);\n+\t\t\t\tif (result != BPF_FLOW_DISSECTOR_CONTINUE) {\n+\t\t\t\t\t__skb_flow_bpf_to_target(\u0026flow_keys,\n+\t\t\t\t\t\t\t\t flow_dissector,\n+\t\t\t\t\t\t\t\t target_container);\n+\t\t\t\t\trcu_read_unlock();\n+\t\t\t\t\treturn result == BPF_OK;\n+\t\t\t\t}\n \t\t\t}\n \t\t}\n+\n+\t\trcu_read_unlock();\n \t}\n \n-\trcu_read_unlock();\n+\t/* Opt-in fast-path; flow_dissect_fast() does the eligibility check\n+\t * and per-shape gating.\n+\t */\n+\tthis_cpu_inc(flow_dissector_pcpu_stats.dissects);\n+\n+\tif (flow_dissect_fast(skb, flow_dissector, target_container,\n+\t\t\t      data, proto, nhoff, hlen, flags))\n+\t\treturn true;\n \n \tif (dissector_uses_key(flow_dissector,\n \t\t\t       FLOW_DISSECTOR_KEY_ETH_ADDRS)) {\n@@ -1200,6 +1991,8 @@ bool __skb_flow_dissect(const struct net *net,\n \t\tkey_num_of_vlans-\u003enum_of_vlans = 0;\n \t}\n \n+\tnhoff_init = nhoff;\n+\n proto_again:\n \tfdret = FLOW_DISSECT_RET_CONTINUE;\n \n@@ -1214,6 +2007,10 @@ bool __skb_flow_dissect(const struct net *net,\n \t\t\tbreak;\n \t\t}\n \n+\t\t/* Top-level eth+IPv4: eth_ip shape candidate (confirmed at out:). */\n+\t\tif (nhoff == nhoff_init)\n+\t\t\teth_ip_top = true;\n+\n \t\tnhoff += iph-\u003eihl * 4;\n \n \t\tip_proto = iph-\u003eprotocol;\n@@ -1262,6 +2059,9 @@ bool __skb_flow_dissect(const struct net *net,\n \t\t\tbreak;\n \t\t}\n \n+\t\tif (nhoff == nhoff_init)\n+\t\t\teth_ip_top = true;\n+\n \t\tip_proto = iph-\u003enexthdr;\n \t\tnhoff += sizeof(struct ipv6hdr);\n \n@@ -1335,8 +2135,12 @@ bool __skb_flow_dissect(const struct net *net,\n \n \t\tif (dissector_vlan == FLOW_DISSECTOR_KEY_MAX) {\n \t\t\tdissector_vlan = FLOW_DISSECTOR_KEY_VLAN;\n+\t\t\t/* First (outer) tag: the vlan fast-path shape. */\n+\t\t\tflow_dissector_count_slow(FLOW_DISSECTOR_SHAPE_VLAN);\n \t\t} else if (dissector_vlan == FLOW_DISSECTOR_KEY_VLAN) {\n \t\t\tdissector_vlan = FLOW_DISSECTOR_KEY_CVLAN;\n+\t\t\t/* Second tag: the qinq (double-tag) fast-path shape. */\n+\t\t\tflow_dissector_count_slow(FLOW_DISSECTOR_SHAPE_QINQ);\n \t\t} else {\n \t\t\tfdret = FLOW_DISSECT_RET_PROTO_AGAIN;\n \t\t\tbreak;\n@@ -1382,6 +2186,8 @@ bool __skb_flow_dissect(const struct net *net,\n \t\t\tbreak;\n \t\t}\n \n+\t\tflow_dissector_count_slow(FLOW_DISSECTOR_SHAPE_PPPOE);\n+\n \t\t/* PFC (compressed 1-byte protocol) frames are not processed.\n \t\t * A compressed protocol field has the least significant bit of\n \t\t * the most significant octet set, which will fail the following\n@@ -1446,6 +2252,7 @@ bool __skb_flow_dissect(const struct net *net,\n \n \tcase htons(ETH_P_MPLS_UC):\n \tcase htons(ETH_P_MPLS_MC):\n+\t\tflow_dissector_count_slow(FLOW_DISSECTOR_SHAPE_MPLS);\n \t\tfdret = __skb_flow_dissect_mpls(skb, flow_dissector,\n \t\t\t\t\t\ttarget_container, data,\n \t\t\t\t\t\tnhoff, hlen, mpls_lse,\n@@ -1543,6 +2350,7 @@ bool __skb_flow_dissect(const struct net *net,\n \t\t\tfdret = FLOW_DISSECT_RET_OUT_GOOD;\n \t\t\tbreak;\n \t\t}\n+\t\tflow_dissector_count_slow(FLOW_DISSECTOR_SHAPE_GRE);\n \n \t\tfdret = __skb_flow_dissect_gre(skb, key_control, flow_dissector,\n \t\t\t\t\t       target_container, data,\n@@ -1605,6 +2413,10 @@ bool __skb_flow_dissect(const struct net *net,\n \t\t\tfdret = FLOW_DISSECT_RET_OUT_GOOD;\n \t\t\tbreak;\n \t\t}\n+\t\t/* Counted below the STOP check: a stop-flagged dissect is\n+\t\t * one the fast path could never have handled.\n+\t\t */\n+\t\tflow_dissector_count_slow(FLOW_DISSECTOR_SHAPE_IPIP);\n \n \t\tproto = htons(ETH_P_IP);\n \n@@ -1696,6 +2508,15 @@ bool __skb_flow_dissect(const struct net *net,\n \tkey_basic-\u003en_proto = proto;\n \tkey_basic-\u003eip_proto = ip_proto;\n \n+\t/* eth_ip shape: top-level eth+IP, TCP/UDP, no encap -- counted here\n+\t * because the fast path returns earlier; with the gate off this is\n+\t * the shape's eligible-fraction signal.\n+\t */\n+\tif (ret \u0026\u0026 eth_ip_top \u0026\u0026\n+\t    !(key_control-\u003eflags \u0026 FLOW_DIS_ENCAPSULATION) \u0026\u0026\n+\t    (ip_proto == IPPROTO_TCP || ip_proto == IPPROTO_UDP))\n+\t\tflow_dissector_count_slow(FLOW_DISSECTOR_SHAPE_ETH_IP);\n+\n \treturn ret;\n \n out_bad:\n@@ -1867,8 +2688,6 @@ void make_flow_keys_digest(struct flow_keys_digest *digest,\n }\n EXPORT_SYMBOL(make_flow_keys_digest);\n \n-static struct flow_dissector flow_keys_dissector_symmetric __read_mostly;\n-\n u32 __skb_get_hash_symmetric_net(const struct net *net, const struct sk_buff *skb)\n {\n \tstruct flow_keys keys;\n@@ -2090,6 +2909,36 @@ EXPORT_SYMBOL(flow_keys_dissector);\n struct flow_dissector flow_keys_basic_dissector __read_mostly;\n EXPORT_SYMBOL(flow_keys_basic_dissector);\n \n+#if IS_ENABLED(CONFIG_FLOW_DISSECTOR_KUNIT_TEST)\n+/* Test-only accessor: the symmetric dissector is file-static but is\n+ * the second dissector the fast-path eligibility gate admits.\n+ */\n+struct flow_dissector *flow_keys_dissector_symmetric_kunit(void)\n+{\n+\treturn \u0026flow_keys_dissector_symmetric;\n+}\n+EXPORT_SYMBOL_GPL(flow_keys_dissector_symmetric_kunit);\n+\n+/* Test-only accessor: summed fast-path hits, the observable for the\n+ * suite's gates-off negative.\n+ */\n+u64 flow_dissector_fast_hits_kunit(void)\n+{\n+\tu64 sum = 0;\n+\tint cpu, i;\n+\n+\tfor_each_possible_cpu(cpu) {\n+\t\tconst struct flow_dissector_stats *s =\n+\t\t\tper_cpu_ptr(\u0026flow_dissector_pcpu_stats, cpu);\n+\n+\t\tfor (i = 0; i \u003c FLOW_DISSECTOR_SHAPE__MAX; i++)\n+\t\t\tsum += READ_ONCE(s-\u003efast_hits[i]);\n+\t}\n+\treturn sum;\n+}\n+EXPORT_SYMBOL_GPL(flow_dissector_fast_hits_kunit);\n+#endif\n+\n static int __init init_default_flow_dissectors(void)\n {\n \tskb_flow_dissector_init(\u0026flow_keys_dissector,\n@@ -2104,3 +2953,176 @@ static int __init init_default_flow_dissectors(void)\n \treturn 0;\n }\n core_initcall(init_default_flow_dissectors);\n+\n+/* Per-shape fast-path sysctls under /proc/sys/net/flow_dissector/. */\n+/* proc_handler for net.flow_dissector.vlan. Writes of 0 also clear\n+ * flow_dissector_qinq_key — QinQ depth-2 is meaningless when the\n+ * outer single-VLAN gate is off, so the slow path would have to\n+ * handle every VLAN-tagged packet anyway.\n+ */\n+static int proc_set_vlan_key(const struct ctl_table *table, int write,\n+\t\t\t     void *buffer, size_t *lenp, loff_t *ppos)\n+{\n+\tint ret;\n+\n+\tret = proc_do_static_key(table, write, buffer, lenp, ppos);\n+\tif (ret == 0 \u0026\u0026 write \u0026\u0026\n+\t    !static_branch_unlikely(\u0026flow_dissector_vlan_key) \u0026\u0026\n+\t    static_branch_unlikely(\u0026flow_dissector_qinq_key))\n+\t\tstatic_branch_disable(\u0026flow_dissector_qinq_key);\n+\treturn ret;\n+}\n+\n+/* proc_handler for net.flow_dissector.qinq. Writes of 1 also enable\n+ * flow_dissector_vlan_key — QinQ extends the VLAN fast-path to depth\n+ * 2; it cannot fire when the depth-0 entry is gated off.\n+ */\n+static int proc_set_qinq_key(const struct ctl_table *table, int write,\n+\t\t\t     void *buffer, size_t *lenp, loff_t *ppos)\n+{\n+\tint ret;\n+\n+\tret = proc_do_static_key(table, write, buffer, lenp, ppos);\n+\tif (ret == 0 \u0026\u0026 write \u0026\u0026\n+\t    static_branch_unlikely(\u0026flow_dissector_qinq_key) \u0026\u0026\n+\t    !static_branch_unlikely(\u0026flow_dissector_vlan_key))\n+\t\tstatic_branch_enable(\u0026flow_dissector_vlan_key);\n+\treturn ret;\n+}\n+\n+static struct ctl_table flow_dissector_sysctl_table[] = {\n+\t{\n+\t\t.procname\t= \"eth_ip\",\n+\t\t.data\t\t= \u0026flow_dissector_eth_ip_key.key,\n+\t\t.maxlen\t\t= sizeof(flow_dissector_eth_ip_key),\n+\t\t.mode\t\t= 0644,\n+\t\t.proc_handler\t= proc_do_static_key,\n+\t},\n+\t{\n+\t\t.procname\t= \"vlan\",\n+\t\t.data\t\t= \u0026flow_dissector_vlan_key.key,\n+\t\t.maxlen\t\t= sizeof(flow_dissector_vlan_key),\n+\t\t.mode\t\t= 0644,\n+\t\t.proc_handler\t= proc_set_vlan_key,\n+\t},\n+\t{\n+\t\t.procname\t= \"qinq\",\n+\t\t.data\t\t= \u0026flow_dissector_qinq_key.key,\n+\t\t.maxlen\t\t= sizeof(flow_dissector_qinq_key),\n+\t\t.mode\t\t= 0644,\n+\t\t.proc_handler\t= proc_set_qinq_key,\n+\t},\n+\t{\n+\t\t.procname\t= \"pppoe\",\n+\t\t.data\t\t= \u0026flow_dissector_pppoe_key.key,\n+\t\t.maxlen\t\t= sizeof(flow_dissector_pppoe_key),\n+\t\t.mode\t\t= 0644,\n+\t\t.proc_handler\t= proc_do_static_key,\n+\t},\n+\t{\n+\t\t.procname\t= \"mpls\",\n+\t\t.data\t\t= \u0026flow_dissector_mpls_key.key,\n+\t\t.maxlen\t\t= sizeof(flow_dissector_mpls_key),\n+\t\t.mode\t\t= 0644,\n+\t\t.proc_handler\t= proc_do_static_key,\n+\t},\n+\t{\n+\t\t.procname\t= \"ipip\",\n+\t\t.data\t\t= \u0026flow_dissector_ipip_key.key,\n+\t\t.maxlen\t\t= sizeof(flow_dissector_ipip_key),\n+\t\t.mode\t\t= 0644,\n+\t\t.proc_handler\t= proc_do_static_key,\n+\t},\n+\t{\n+\t\t.procname\t= \"gre\",\n+\t\t.data\t\t= \u0026flow_dissector_gre_key.key,\n+\t\t.maxlen\t\t= sizeof(flow_dissector_gre_key),\n+\t\t.mode\t\t= 0644,\n+\t\t.proc_handler\t= proc_do_static_key,\n+\t},\n+};\n+\n+static const char * const flow_dissector_shape_names[FLOW_DISSECTOR_SHAPE__MAX] = {\n+\t[FLOW_DISSECTOR_SHAPE_ETH_IP] = \"eth_ip\",\n+\t[FLOW_DISSECTOR_SHAPE_VLAN]   = \"vlan\",\n+\t[FLOW_DISSECTOR_SHAPE_QINQ]   = \"qinq\",\n+\t[FLOW_DISSECTOR_SHAPE_PPPOE]  = \"pppoe\",\n+\t[FLOW_DISSECTOR_SHAPE_MPLS]   = \"mpls\",\n+\t[FLOW_DISSECTOR_SHAPE_IPIP]   = \"ipip\",\n+\t[FLOW_DISSECTOR_SHAPE_GRE]    = \"gre\",\n+};\n+\n+static bool flow_dissector_shape_gate(enum flow_dissector_shape shape)\n+{\n+\tswitch (shape) {\n+\tcase FLOW_DISSECTOR_SHAPE_ETH_IP:\n+\t\treturn static_key_enabled(\u0026flow_dissector_eth_ip_key);\n+\tcase FLOW_DISSECTOR_SHAPE_VLAN:\n+\t\treturn static_key_enabled(\u0026flow_dissector_vlan_key);\n+\tcase FLOW_DISSECTOR_SHAPE_QINQ:\n+\t\treturn static_key_enabled(\u0026flow_dissector_qinq_key);\n+\tcase FLOW_DISSECTOR_SHAPE_PPPOE:\n+\t\treturn static_key_enabled(\u0026flow_dissector_pppoe_key);\n+\tcase FLOW_DISSECTOR_SHAPE_MPLS:\n+\t\treturn static_key_enabled(\u0026flow_dissector_mpls_key);\n+\tcase FLOW_DISSECTOR_SHAPE_IPIP:\n+\t\treturn static_key_enabled(\u0026flow_dissector_ipip_key);\n+\tcase FLOW_DISSECTOR_SHAPE_GRE:\n+\t\treturn static_key_enabled(\u0026flow_dissector_gre_key);\n+\tdefault:\n+\t\treturn false;\n+\t}\n+}\n+\n+/* /proc/net/flow_dissector_stats: per-shape occurrences (slow path),\n+ * fast_hits, and eligible% = (occurrences + fast_hits) / dissects --\n+ * the signal a policy layer thresholds against a per-shape\n+ * break-even.\n+ */\n+static int flow_dissector_stats_show(struct seq_file *seq, void *v)\n+{\n+\tu64 occ[FLOW_DISSECTOR_SHAPE__MAX] = {};\n+\tu64 fast[FLOW_DISSECTOR_SHAPE__MAX] = {};\n+\tu64 dissects = 0;\n+\tint cpu, i;\n+\n+\tfor_each_possible_cpu(cpu) {\n+\t\tconst struct flow_dissector_stats *s =\n+\t\t\tper_cpu_ptr(\u0026flow_dissector_pcpu_stats, cpu);\n+\n+\t\tfor (i = 0; i \u003c FLOW_DISSECTOR_SHAPE__MAX; i++) {\n+\t\t\tocc[i]  += READ_ONCE(s-\u003eoccurrences[i]);\n+\t\t\tfast[i] += READ_ONCE(s-\u003efast_hits[i]);\n+\t\t}\n+\t\tdissects += READ_ONCE(s-\u003edissects);\n+\t}\n+\n+\tseq_printf(seq, \"%-8s %16s %16s %10s %5s\\n\",\n+\t\t   \"shape\", \"occurrences\", \"fast_hits\", \"eligible%\", \"gate\");\n+\tfor (i = 0; i \u003c FLOW_DISSECTOR_SHAPE__MAX; i++) {\n+\t\tu64 total = occ[i] + fast[i];\n+\t\tu64 pct_x100 = dissects ? div64_u64(total * 10000, dissects) : 0;\n+\n+\t\tseq_printf(seq, \"%-8s %16llu %16llu %7llu.%02llu %5s\\n\",\n+\t\t\t   flow_dissector_shape_names[i], occ[i], fast[i],\n+\t\t\t   pct_x100 / 100, pct_x100 % 100,\n+\t\t\t   str_on_off(flow_dissector_shape_gate(i)));\n+\t}\n+\tseq_printf(seq, \"dissects: %llu\\n\", dissects);\n+\treturn 0;\n+}\n+\n+static int __init flow_dissector_sysctl_init(void)\n+{\n+\tif (!register_net_sysctl(\u0026init_net, \"net/flow_dissector\",\n+\t\t\t\t flow_dissector_sysctl_table))\n+\t\treturn -ENOMEM;\n+\n+\t/* Global (init_net) counters — matches the global gates; per-netns\n+\t * is a noted follow-up. A missing proc file is not fatal.\n+\t */\n+\tproc_create_single(\"flow_dissector_stats\", 0444, init_net.proc_net,\n+\t\t\t   flow_dissector_stats_show);\n+\treturn 0;\n+}\n+late_initcall(flow_dissector_sysctl_init);\ndiff --git a/net/core/flow_dissector_test.c b/net/core/flow_dissector_test.c\nnew file mode 100644\nindex 00000000000000..e0014affda7f93\n--- /dev/null\n+++ b/net/core/flow_dissector_test.c\n@@ -0,0 +1,1053 @@\n+// SPDX-License-Identifier: GPL-2.0-or-later\n+/*\n+ * KUnit equivalence tests for the flow dissector opt-in fast paths.\n+ *\n+ * Every fast-path shape contracts to be byte-identical with the slow\n+ * path. Each corpus packet is dissected twice into zeroed containers\n+ * -- gates off, then gates on -- and the return values, the full\n+ * struct flow_keys and flow_hash_from_keys() must match exactly, for\n+ * both eligible dissectors (flow_keys_dissector and the file-static\n+ * symmetric one). (A fast-path miss cannot leak partial writes to\n+ * callers: flow_dissect_fast() is only invoked from\n+ * __skb_flow_dissect(), which continues into the full slow-path walk\n+ * on the same container whenever the fast path returns false.)\n+ */\n+\n+#include \u003ckunit/test.h\u003e\n+\n+#include \u003clinux/etherdevice.h\u003e\n+#include \u003clinux/if_ether.h\u003e\n+#include \u003clinux/if_pppox.h\u003e\n+#include \u003clinux/if_tunnel.h\u003e\n+#include \u003clinux/if_vlan.h\u003e\n+#include \u003clinux/ip.h\u003e\n+#include \u003clinux/ipv6.h\u003e\n+#include \u003clinux/mpls.h\u003e\n+#include \u003clinux/netdevice.h\u003e\n+#include \u003clinux/ppp_defs.h\u003e\n+#include \u003clinux/prandom.h\u003e\n+#include \u003clinux/skbuff.h\u003e\n+#include \u003clinux/udp.h\u003e\n+#include \u003cnet/flow_dissector.h\u003e\n+#include \u003cnet/gre.h\u003e\n+#include \u003cnet/ip.h\u003e\n+#include \u003cnet/net_namespace.h\u003e\n+\n+#define FD_TEST_BUF_LEN 512\n+#define FD_FUZZ_ITERS 4000\n+\n+/* The byte-identical fast-path gates. */\n+static struct static_key_false * const fd_fast_gates[] = {\n+\t\u0026flow_dissector_eth_ip_key,\n+\t\u0026flow_dissector_vlan_key,\n+\t\u0026flow_dissector_qinq_key,\n+\t\u0026flow_dissector_pppoe_key,\n+\t\u0026flow_dissector_mpls_key,\n+\t\u0026flow_dissector_ipip_key,\n+\t\u0026flow_dissector_gre_key,\n+};\n+\n+static void fd_fast_gates_set(bool on)\n+{\n+\tint i;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(fd_fast_gates); i++) {\n+\t\tif (on)\n+\t\t\tstatic_branch_enable(fd_fast_gates[i]);\n+\t\telse\n+\t\t\tstatic_branch_disable(fd_fast_gates[i]);\n+\t}\n+}\n+\n+/* --- packet builders (network-layer payloads; __skb_flow_dissect is\n+ * called in raw-data mode with the L3 proto passed explicitly, so no\n+ * Ethernet header is included) ---\n+ */\n+\n+static int put_ports(u8 *buf)\n+{\n+\t__be16 *p = (__be16 *)buf;\n+\n+\tp[0] = htons(0x1234);\n+\tp[1] = htons(0x5678);\n+\treturn 4;\n+}\n+\n+static int put_ipv4(u8 *buf, u8 ip_proto, u8 ihl, __be16 frag_off)\n+{\n+\tstruct iphdr *ip = (struct iphdr *)buf;\n+\tint hdrlen = ihl * 4;\n+\n+\tmemset(ip, 0, hdrlen);\n+\tip-\u003eversion = 4;\n+\tip-\u003eihl = ihl;\n+\tip-\u003ettl = 64;\n+\tip-\u003etot_len = htons(hdrlen + 4);\n+\tip-\u003efrag_off = frag_off;\n+\tip-\u003eprotocol = ip_proto;\n+\tip-\u003esaddr = htonl(0xc0a80101);\t/* 192.168.1.1 */\n+\tip-\u003edaddr = htonl(0xc0a80202);\t/* 192.168.2.2 */\n+\treturn hdrlen;\n+}\n+\n+static int put_ipv6(u8 *buf, u8 nexthdr, u32 flow_label)\n+{\n+\tstruct ipv6hdr *ip6 = (struct ipv6hdr *)buf;\n+\n+\tmemset(ip6, 0, sizeof(*ip6));\n+\tip6-\u003eversion = 6;\n+\tip6-\u003eflow_lbl[0] = (flow_label \u003e\u003e 16) \u0026 0x0f;\n+\tip6-\u003eflow_lbl[1] = (flow_label \u003e\u003e 8) \u0026 0xff;\n+\tip6-\u003eflow_lbl[2] = flow_label \u0026 0xff;\n+\tip6-\u003epayload_len = htons(4);\n+\tip6-\u003enexthdr = nexthdr;\n+\tip6-\u003ehop_limit = 64;\n+\tip6-\u003esaddr.s6_addr32[0] = htonl(0x20010db8);\n+\tip6-\u003esaddr.s6_addr32[3] = htonl(1);\n+\tip6-\u003edaddr.s6_addr32[0] = htonl(0x20010db8);\n+\tip6-\u003edaddr.s6_addr32[3] = htonl(2);\n+\treturn sizeof(*ip6);\n+}\n+\n+static int put_vlan(u8 *buf, u16 tci, __be16 inner_proto)\n+{\n+\tstruct vlan_hdr *vlan = (struct vlan_hdr *)buf;\n+\n+\tvlan-\u003eh_vlan_TCI = htons(tci);\n+\tvlan-\u003eh_vlan_encapsulated_proto = inner_proto;\n+\treturn sizeof(*vlan);\n+}\n+\n+static int put_pppoe(u8 *buf, u16 ppp_proto, u16 payload_len)\n+{\n+\tstruct pppoe_hdr *hdr = (struct pppoe_hdr *)buf;\n+\t__be16 *proto = (__be16 *)(buf + sizeof(*hdr));\n+\n+\tmemset(hdr, 0, sizeof(*hdr));\n+\thdr-\u003ever = 1;\n+\thdr-\u003etype = 1;\n+\thdr-\u003ecode = 0;\n+\thdr-\u003esid = htons(0x42);\n+\thdr-\u003elength = htons(payload_len + 2);\n+\t*proto = htons(ppp_proto);\n+\treturn sizeof(*hdr) + 2;\n+}\n+\n+static int put_mpls(u8 *buf, u32 label, u32 bos)\n+{\n+\tstruct mpls_label *lse = (struct mpls_label *)buf;\n+\n+\tlse-\u003eentry = htonl((label \u003c\u003c MPLS_LS_LABEL_SHIFT) |\n+\t\t\t   (bos \u003c\u003c MPLS_LS_S_SHIFT) |\n+\t\t\t   (64 \u003c\u003c MPLS_LS_TTL_SHIFT));\n+\treturn sizeof(*lse);\n+}\n+\n+static int put_gre(u8 *buf, __be16 flags, __be16 protocol)\n+{\n+\tstruct gre_base_hdr *gre = (struct gre_base_hdr *)buf;\n+\n+\tgre-\u003eflags = flags;\n+\tgre-\u003eprotocol = protocol;\n+\treturn sizeof(*gre);\n+}\n+\n+/* --- composite builders, one per corpus entry --- */\n+\n+static int build_ipv4_tcp(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_TCP, 5, 0);\n+\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_ipv4_udp(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_UDP, 5, 0);\n+\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_ipv6_tcp(u8 *buf)\n+{\n+\tint n = put_ipv6(buf, IPPROTO_TCP, 0);\n+\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_ipv6_udp(u8 *buf)\n+{\n+\tint n = put_ipv6(buf, IPPROTO_UDP, 0);\n+\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_vlan_ipv4_tcp(u8 *buf)\n+{\n+\tint n = put_vlan(buf, 100, htons(ETH_P_IP));\n+\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_vlan_ipv6_udp(u8 *buf)\n+{\n+\tint n = put_vlan(buf, 100, htons(ETH_P_IPV6));\n+\n+\tn += put_ipv6(buf + n, IPPROTO_UDP, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_qinq_ipv4_tcp(u8 *buf)\n+{\n+\tint n = put_vlan(buf, 100, htons(ETH_P_8021Q));\n+\n+\tn += put_vlan(buf + n, 200, htons(ETH_P_IP));\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_vlan3_ipv4_tcp(u8 *buf)\n+{\n+\tint n = put_vlan(buf, 100, htons(ETH_P_8021Q));\n+\n+\tn += put_vlan(buf + n, 200, htons(ETH_P_8021Q));\n+\tn += put_vlan(buf + n, 300, htons(ETH_P_IP));\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_pppoe_ipv4_tcp(u8 *buf)\n+{\n+\tint n = put_pppoe(buf, PPP_IP, 20 + 4);\n+\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_pppoe_ipv6_tcp(u8 *buf)\n+{\n+\tint n = put_pppoe(buf, PPP_IPV6, 40 + 4);\n+\n+\tn += put_ipv6(buf + n, IPPROTO_TCP, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_pppoe_lcp(u8 *buf)\n+{\n+\tint n = put_pppoe(buf, PPP_LCP, 4);\n+\tu8 lcp[4] = { 0x01, 0x01, 0x00, 0x04 };\n+\n+\tmemcpy(buf + n, lcp, sizeof(lcp));\n+\treturn n + sizeof(lcp);\n+}\n+\n+static int build_mpls_ipv4(u8 *buf)\n+{\n+\tint n = put_mpls(buf, 1000, 1);\n+\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_mpls_multi(u8 *buf)\n+{\n+\tint n = put_mpls(buf, 1000, 0);\t/* S=0: not bottom of stack */\n+\n+\tn += put_mpls(buf + n, 2000, 1);\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_ipip(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_IPIP, 5, 0);\n+\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_6in4(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_IPV6, 5, 0);\n+\n+\tn += put_ipv6(buf + n, IPPROTO_TCP, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_4in6(u8 *buf)\n+{\n+\tint n = put_ipv6(buf, IPPROTO_IPIP, 0);\n+\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_4in6_flowlabel(u8 *buf)\n+{\n+\tint n = put_ipv6(buf, IPPROTO_IPIP, 0xbeef);\n+\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_6in6(u8 *buf)\n+{\n+\tint n = put_ipv6(buf, IPPROTO_IPV6, 0);\n+\n+\tn += put_ipv6(buf + n, IPPROTO_TCP, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_gre_ipv4(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_GRE, 5, 0);\n+\n+\tn += put_gre(buf + n, 0, htons(ETH_P_IP));\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_gre_ipv6(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_GRE, 5, 0);\n+\n+\tn += put_gre(buf + n, 0, htons(ETH_P_IPV6));\n+\tn += put_ipv6(buf + n, IPPROTO_TCP, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_gre6_ipv6(u8 *buf)\n+{\n+\tint n = put_ipv6(buf, IPPROTO_GRE, 0);\n+\n+\tn += put_gre(buf + n, 0, htons(ETH_P_IPV6));\n+\tn += put_ipv6(buf + n, IPPROTO_TCP, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_gre6_ipv4(u8 *buf)\n+{\n+\tint n = put_ipv6(buf, IPPROTO_GRE, 0);\n+\n+\tn += put_gre(buf + n, 0, htons(ETH_P_IP));\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+/* --- corner-case builders --- */\n+\n+/* GRE variants that must defer (any non-zero flags/version word). */\n+static int build_gre_seq_ipv4(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_GRE, 5, 0);\n+\n+\tn += put_gre(buf + n, GRE_SEQ, htons(ETH_P_IP));\n+\tmemset(buf + n, 0, 4);\t\t/* sequence number */\n+\tn += 4;\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_gre_key_ipv4(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_GRE, 5, 0);\n+\n+\tn += put_gre(buf + n, GRE_KEY, htons(ETH_P_IP));\n+\tmemset(buf + n, 0, 4);\t\t/* key */\n+\tn += 4;\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_gre_version1(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_GRE, 5, 0);\n+\n+\t/* GRE version 1 (PPTP) lives in the low bits of the flags word. */\n+\tn += put_gre(buf + n, htons(0x0001), htons(ETH_P_IP));\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_gre_teb(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_GRE, 5, 0);\n+\n+\t/* Transparent Ethernet bridging inner: fast path defers. */\n+\tn += put_gre(buf + n, 0, htons(ETH_P_TEB));\n+\treturn n + put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+}\n+\n+/* An IPv6 extension header (8 bytes, hdrlen field 0). */\n+static int put_ext_hdr(u8 *buf, u8 next_proto)\n+{\n+\tmemset(buf, 0, 8);\n+\tbuf[0] = next_proto;\n+\tbuf[1] = 0;\t\t\t/* hdr ext len: (0 + 1) * 8 = 8 bytes */\n+\treturn 8;\n+}\n+\n+static int build_ipv6_hopopts_dest_tcp(u8 *buf)\n+{\n+\tint n = put_ipv6(buf, IPPROTO_HOPOPTS, 0);\n+\n+\tn += put_ext_hdr(buf + n, IPPROTO_DSTOPTS);\n+\tn += put_ext_hdr(buf + n, IPPROTO_TCP);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_ipv6_frag_tcp(u8 *buf)\n+{\n+\tint n = put_ipv6(buf, IPPROTO_FRAGMENT, 0);\n+\n+\tmemset(buf + n, 0, 8);\n+\tbuf[n] = IPPROTO_TCP;\t\t/* fragment header, offset 0 */\n+\t*(__be32 *)(buf + n + 4) = htonl(0x12345678);\n+\tn += 8;\n+\treturn n + put_ports(buf + n);\n+}\n+\n+/* TPID ordering not covered elsewhere: 8021Q outer, 8021AD inner. */\n+static int build_vlan_q_then_ad_ipv4(u8 *buf)\n+{\n+\tint n = put_vlan(buf, 100, htons(ETH_P_8021AD));\n+\n+\tn += put_vlan(buf + n, 200, htons(ETH_P_IP));\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+/* IPv4 with a larger options block (IHL 8 =\u003e 12 bytes of options). */\n+static int build_ipv4_options12_tcp(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_TCP, 8, 0);\n+\n+\treturn n + put_ports(buf + n);\n+}\n+\n+/* PPPoE with a PFC-compressed (odd MSB) PPP protocol field: defers. */\n+static int build_pppoe_pfc(u8 *buf)\n+{\n+\tint n = put_pppoe(buf, 0x2100, 20 + 4);\n+\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+/* Mid-stream fragment: non-zero offset AND MF still set. */\n+static int build_ipv4_frag_mid_tcp(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_TCP, 5, htons(IP_MF | 5));\n+\n+\treturn n + put_ports(buf + n);\n+}\n+\n+/* GRE optional-field combinations (order: csum+reserved, key, seq). */\n+static int build_gre_csum_key_ipv4(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_GRE, 5, 0);\n+\n+\tn += put_gre(buf + n, GRE_CSUM | GRE_KEY, htons(ETH_P_IP));\n+\tmemset(buf + n, 0, 8);\t\t/* checksum + reserved, key */\n+\tn += 8;\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_gre_csum_key_seq_ipv4(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_GRE, 5, 0);\n+\n+\tn += put_gre(buf + n, GRE_CSUM | GRE_KEY | GRE_SEQ, htons(ETH_P_IP));\n+\tmemset(buf + n, 0, 12);\t\t/* checksum + reserved, key, seq */\n+\tn += 12;\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+/* Priority-tagged frame (802.1Q VID 0, only PCP bits in the TCI). */\n+static int build_vlan_prio_ipv4_tcp(u8 *buf)\n+{\n+\tint n = put_vlan(buf, 5 \u003c\u003c VLAN_PRIO_SHIFT, htons(ETH_P_IP));\n+\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+/* IPv6 routing extension header before TCP. */\n+static int build_ipv6_routing_tcp(u8 *buf)\n+{\n+\tint n = put_ipv6(buf, IPPROTO_ROUTING, 0);\n+\n+\tn += put_ext_hdr(buf + n, IPPROTO_TCP);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+/* Deeply nested IPIP / GRE chains for the recursion cap. */\n+static int build_ipip_nest(u8 *buf, int levels)\n+{\n+\tint n = 0, i;\n+\n+\tfor (i = 0; i \u003c levels; i++)\n+\t\tn += put_ipv4(buf + n, IPPROTO_IPIP, 5, 0);\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_gre_nest(u8 *buf, int levels)\n+{\n+\tint n = 0, i;\n+\n+\tfor (i = 0; i \u003c levels; i++) {\n+\t\tn += put_ipv4(buf + n, IPPROTO_GRE, 5, 0);\n+\t\tn += put_gre(buf + n, 0, htons(ETH_P_IP));\n+\t}\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_gre_csum_ipv4(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_GRE, 5, 0);\n+\n+\tn += put_gre(buf + n, GRE_CSUM, htons(ETH_P_IP));\n+\tmemset(buf + n, 0, 4);\t\t/* checksum + reserved */\n+\tn += 4;\n+\tn += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_ipv4_options_tcp(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_TCP, 6, 0);\t/* IHL=6: 4B options */\n+\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_ipv4_frag_tcp(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_TCP, 5, htons(IP_MF));\n+\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_ipv4_frag_offset_tcp(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_TCP, 5, htons(0x0010));\n+\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_ipv4_icmp(u8 *buf)\n+{\n+\tint n = put_ipv4(buf, IPPROTO_ICMP, 5, 0);\n+\tu8 icmp[8] = { 0x08, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x01 };\n+\n+\tmemcpy(buf + n, icmp, sizeof(icmp));\n+\treturn n + sizeof(icmp);\n+}\n+\n+static int build_ipv6_hopopts_tcp(u8 *buf)\n+{\n+\tint n = put_ipv6(buf, IPPROTO_HOPOPTS, 0);\n+\tu8 hbh[8] = { IPPROTO_TCP, 0, 0, 0, 0, 0, 0, 0 };\n+\n+\tmemcpy(buf + n, hbh, sizeof(hbh));\n+\tn += sizeof(hbh);\n+\treturn n + put_ports(buf + n);\n+}\n+\n+static int build_ipv6_flowlabel_tcp(u8 *buf)\n+{\n+\tint n = put_ipv6(buf, IPPROTO_TCP, 0xbeef);\n+\n+\treturn n + put_ports(buf + n);\n+}\n+\n+struct fd_fast_case {\n+\tconst char *name;\n+\tint (*build)(u8 *buf);\n+\t__be16 proto;\n+\tunsigned int flags;\n+};\n+\n+/* htons() is not constant-foldable here without cpu_to_be16 literals;\n+ * use cpu_to_be16 for static initializers.\n+ */\n+static const struct fd_fast_case fd_fast_cases[] = {\n+\t/* eligible shapes: the fast path should take these */\n+\t{ \"ipv4_tcp\", build_ipv4_tcp, cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"ipv4_udp\", build_ipv4_udp, cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"ipv6_tcp\", build_ipv6_tcp, cpu_to_be16(ETH_P_IPV6), 0 },\n+\t{ \"ipv6_udp\", build_ipv6_udp, cpu_to_be16(ETH_P_IPV6), 0 },\n+\t{ \"vlan_ipv4_tcp\", build_vlan_ipv4_tcp, cpu_to_be16(ETH_P_8021Q), 0 },\n+\t{ \"vlan_ipv6_udp\", build_vlan_ipv6_udp, cpu_to_be16(ETH_P_8021Q), 0 },\n+\t{ \"qinq_ipv4_tcp\", build_qinq_ipv4_tcp, cpu_to_be16(ETH_P_8021AD), 0 },\n+\t{ \"pppoe_ipv4_tcp\", build_pppoe_ipv4_tcp, cpu_to_be16(ETH_P_PPP_SES), 0 },\n+\t{ \"pppoe_ipv6_tcp\", build_pppoe_ipv6_tcp, cpu_to_be16(ETH_P_PPP_SES), 0 },\n+\t{ \"mpls_ipv4\", build_mpls_ipv4, cpu_to_be16(ETH_P_MPLS_UC), 0 },\n+\t{ \"ipip\", build_ipip, cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"6in4\", build_6in4, cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"4in6\", build_4in6, cpu_to_be16(ETH_P_IPV6), 0 },\n+\t{ \"4in6_flowlabel\", build_4in6_flowlabel, cpu_to_be16(ETH_P_IPV6), 0 },\n+\t{ \"6in6\", build_6in6, cpu_to_be16(ETH_P_IPV6), 0 },\n+\t{ \"gre_ipv4\", build_gre_ipv4, cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"gre6_ipv4\", build_gre6_ipv4, cpu_to_be16(ETH_P_IPV6), 0 },\n+\t{ \"gre_ipv6\", build_gre_ipv6, cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"gre6_ipv6\", build_gre6_ipv6, cpu_to_be16(ETH_P_IPV6), 0 },\n+\t/* deliberate fast-path misses: must fall back with identical\n+\t * output (and, per the zeroed containers, no partial writes)\n+\t */\n+\t{ \"ipv4_options_tcp\", build_ipv4_options_tcp, cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"ipv4_frag_mf\", build_ipv4_frag_tcp, cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"ipv4_frag_mf_1stfrag\", build_ipv4_frag_tcp, cpu_to_be16(ETH_P_IP),\n+\t  FLOW_DISSECTOR_F_PARSE_1ST_FRAG },\n+\t{ \"ipv4_frag_offset\", build_ipv4_frag_offset_tcp,\n+\t  cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"ipv4_icmp\", build_ipv4_icmp, cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"ipv6_hopopts_tcp\", build_ipv6_hopopts_tcp,\n+\t  cpu_to_be16(ETH_P_IPV6), 0 },\n+\t{ \"ipv6_flowlabel_tcp\", build_ipv6_flowlabel_tcp,\n+\t  cpu_to_be16(ETH_P_IPV6), 0 },\n+\t{ \"vlan3_ipv4_tcp\", build_vlan3_ipv4_tcp, cpu_to_be16(ETH_P_8021Q), 0 },\n+\t{ \"pppoe_lcp\", build_pppoe_lcp, cpu_to_be16(ETH_P_PPP_SES), 0 },\n+\t{ \"mpls_multi_label\", build_mpls_multi, cpu_to_be16(ETH_P_MPLS_UC), 0 },\n+\t{ \"gre_csum_ipv4\", build_gre_csum_ipv4, cpu_to_be16(ETH_P_IP), 0 },\n+\t/* corner cases */\n+\t{ \"gre_seq_ipv4\", build_gre_seq_ipv4, cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"gre_key_ipv4\", build_gre_key_ipv4, cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"gre_version1\", build_gre_version1, cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"gre_teb\", build_gre_teb, cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"ipv6_hopopts_dest_tcp\", build_ipv6_hopopts_dest_tcp,\n+\t  cpu_to_be16(ETH_P_IPV6), 0 },\n+\t{ \"ipv6_frag_tcp\", build_ipv6_frag_tcp, cpu_to_be16(ETH_P_IPV6), 0 },\n+\t{ \"vlan_q_then_ad_ipv4\", build_vlan_q_then_ad_ipv4,\n+\t  cpu_to_be16(ETH_P_8021Q), 0 },\n+\t{ \"ipv4_options12_tcp\", build_ipv4_options12_tcp,\n+\t  cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"pppoe_pfc\", build_pppoe_pfc, cpu_to_be16(ETH_P_PPP_SES), 0 },\n+\t{ \"ipv4_frag_mid\", build_ipv4_frag_mid_tcp, cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"ipv4_frag_mid_1stfrag\", build_ipv4_frag_mid_tcp,\n+\t  cpu_to_be16(ETH_P_IP), FLOW_DISSECTOR_F_PARSE_1ST_FRAG },\n+\t{ \"gre_csum_key_ipv4\", build_gre_csum_key_ipv4,\n+\t  cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"gre_csum_key_seq_ipv4\", build_gre_csum_key_seq_ipv4,\n+\t  cpu_to_be16(ETH_P_IP), 0 },\n+\t{ \"vlan_prio_ipv4_tcp\", build_vlan_prio_ipv4_tcp,\n+\t  cpu_to_be16(ETH_P_8021Q), 0 },\n+\t{ \"ipv6_routing_tcp\", build_ipv6_routing_tcp,\n+\t  cpu_to_be16(ETH_P_IPV6), 0 },\n+};\n+\n+static void fd_fast_case_to_desc(const struct fd_fast_case *c, char *desc)\n+{\n+\tstrscpy(desc, c-\u003ename, KUNIT_PARAM_DESC_SIZE);\n+}\n+\n+KUNIT_ARRAY_PARAM(fd_fast, fd_fast_cases, fd_fast_case_to_desc);\n+\n+/* Dissect with gates off then on; returns and output must match. */\n+static void fd_check_one(struct kunit *test, struct flow_dissector *fd,\n+\t\t\t const u8 *data, __be16 proto, int hlen,\n+\t\t\t unsigned int flags)\n+{\n+\tstruct flow_keys keys_slow, keys_fast;\n+\tbool ret_slow, ret_fast;\n+\n+\tfd_fast_gates_set(false);\n+\tmemset(\u0026keys_slow, 0, sizeof(keys_slow));\n+\tret_slow = __skb_flow_dissect(\u0026init_net, NULL, fd, \u0026keys_slow,\n+\t\t\t\t      data, proto, 0, hlen, flags);\n+\n+\tfd_fast_gates_set(true);\n+\tmemset(\u0026keys_fast, 0, sizeof(keys_fast));\n+\tret_fast = __skb_flow_dissect(\u0026init_net, NULL, fd, \u0026keys_fast,\n+\t\t\t\t      data, proto, 0, hlen, flags);\n+\tfd_fast_gates_set(false);\n+\n+\tKUNIT_EXPECT_EQ(test, ret_slow, ret_fast);\n+\tKUNIT_EXPECT_MEMEQ(test, \u0026keys_slow, \u0026keys_fast, sizeof(keys_slow));\n+\t/* flow_keys -\u003e skb-\u003ehash is what consumers see; assert it too. */\n+\tKUNIT_EXPECT_EQ(test, flow_hash_from_keys(\u0026keys_slow),\n+\t\t\tflow_hash_from_keys(\u0026keys_fast));\n+}\n+\n+/* Check against both eligible dissectors (different used_keys). */\n+static void fd_fast_check_equiv(struct kunit *test, const u8 *data,\n+\t\t\t\t__be16 proto, int hlen, unsigned int flags)\n+{\n+\t/* skb_get_hash() passes STOP_AT_FLOW_LABEL on every dissect; each\n+\t * case must hold with and without it.\n+\t */\n+\tunsigned int fl = flags | FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL;\n+\n+\tfd_check_one(test, \u0026flow_keys_dissector, data, proto, hlen, flags);\n+\tfd_check_one(test, flow_keys_dissector_symmetric_kunit(),\n+\t\t     data, proto, hlen, flags);\n+\tfd_check_one(test, \u0026flow_keys_dissector, data, proto, hlen, fl);\n+\tfd_check_one(test, flow_keys_dissector_symmetric_kunit(),\n+\t\t     data, proto, hlen, fl);\n+}\n+\n+static void fd_fast_equiv_test(struct kunit *test)\n+{\n+\tconst struct fd_fast_case *c = test-\u003eparam_value;\n+\tu8 *buf;\n+\tint len;\n+\n+\tbuf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);\n+\n+\tlen = c-\u003ebuild(buf);\n+\tKUNIT_ASSERT_LE(test, len, FD_TEST_BUF_LEN);\n+\n+\tfd_fast_check_equiv(test, buf, c-\u003eproto, len, c-\u003eflags);\n+}\n+\n+/* Truncation sweep: the fast path must never parse (or partially\n+ * write) anything the slow path rejected at the same length.\n+ */\n+static void fd_fast_truncation_test(struct kunit *test)\n+{\n+\tint i, len, hlen;\n+\tu8 *buf;\n+\n+\tbuf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(fd_fast_cases); i++) {\n+\t\tconst struct fd_fast_case *c = \u0026fd_fast_cases[i];\n+\n+\t\tlen = c-\u003ebuild(buf);\n+\t\tfor (hlen = len - 1; hlen \u003e= 0; hlen--)\n+\t\t\tfd_fast_check_equiv(test, buf, c-\u003eproto, hlen,\n+\t\t\t\t\t    c-\u003eflags);\n+\t}\n+}\n+\n+/* skb-mode builder (for hw-accel VLAN entry conditions). */\n+static struct sk_buff *fd_fast_build_skb(struct kunit *test,\n+\t\t\t\t\t int (*build)(u8 *buf),\n+\t\t\t\t\t __be16 protocol)\n+{\n+\tstruct sk_buff *skb;\n+\tint len;\n+\tu8 *buf;\n+\n+\tbuf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);\n+\tlen = build(buf);\n+\n+\tskb = alloc_skb(FD_TEST_BUF_LEN + NET_SKB_PAD, GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, skb);\n+\tskb_reserve(skb, NET_SKB_PAD);\n+\tskb_put_data(skb, buf, len);\n+\tskb-\u003eprotocol = protocol;\n+\tskb_reset_mac_header(skb);\n+\tskb_reset_network_header(skb);\n+\treturn skb;\n+}\n+\n+static void fd_check_one_skb(struct kunit *test, struct flow_dissector *fd,\n+\t\t\t     struct sk_buff *skb)\n+{\n+\tstruct flow_keys keys_slow, keys_fast;\n+\tbool ret_slow, ret_fast;\n+\n+\tfd_fast_gates_set(false);\n+\tmemset(\u0026keys_slow, 0, sizeof(keys_slow));\n+\tret_slow = __skb_flow_dissect(\u0026init_net, skb, fd,\n+\t\t\t\t      \u0026keys_slow, NULL, 0, 0, 0, 0);\n+\n+\tfd_fast_gates_set(true);\n+\tmemset(\u0026keys_fast, 0, sizeof(keys_fast));\n+\tret_fast = __skb_flow_dissect(\u0026init_net, skb, fd,\n+\t\t\t\t      \u0026keys_fast, NULL, 0, 0, 0, 0);\n+\tfd_fast_gates_set(false);\n+\n+\tKUNIT_EXPECT_EQ(test, ret_slow, ret_fast);\n+\tKUNIT_EXPECT_MEMEQ(test, \u0026keys_slow, \u0026keys_fast, sizeof(keys_slow));\n+\tKUNIT_EXPECT_EQ(test, flow_hash_from_keys(\u0026keys_slow),\n+\t\t\tflow_hash_from_keys(\u0026keys_fast));\n+}\n+\n+static void fd_fast_check_equiv_skb(struct kunit *test, struct sk_buff *skb)\n+{\n+\tfd_check_one_skb(test, \u0026flow_keys_dissector, skb);\n+\tfd_check_one_skb(test, flow_keys_dissector_symmetric_kunit(), skb);\n+}\n+\n+static void fd_fast_skb_plain_test(struct kunit *test)\n+{\n+\tstruct sk_buff *skb;\n+\n+\tskb = fd_fast_build_skb(test, build_ipv4_tcp, htons(ETH_P_IP));\n+\tfd_fast_check_equiv_skb(test, skb);\n+\tkfree_skb(skb);\n+}\n+\n+static void fd_fast_skb_hwaccel_vlan_test(struct kunit *test)\n+{\n+\tstruct sk_buff *skb;\n+\n+\t/* Plain payload; VLAN tag in skb metadata, as after hw stripping. */\n+\tskb = fd_fast_build_skb(test, build_ipv4_tcp, htons(ETH_P_IP));\n+\t__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), 100);\n+\tfd_fast_check_equiv_skb(test, skb);\n+\tkfree_skb(skb);\n+}\n+\n+static void fd_fast_skb_hwaccel_vlan_qinq_test(struct kunit *test)\n+{\n+\tstruct sk_buff *skb;\n+\n+\t/* Outer tag hw-stripped (8021AD), second tag in the payload. */\n+\tskb = fd_fast_build_skb(test, build_vlan_ipv4_tcp, htons(ETH_P_8021Q));\n+\t__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021AD), 100);\n+\tfd_fast_check_equiv_skb(test, skb);\n+\tkfree_skb(skb);\n+}\n+\n+/* Nested tunnels: both paths must stop at MAX_FLOW_DISSECT_HDRS --\n+ * shallow stacks descend, past the cap the fast path defers and\n+ * matches the slow path's capped result.\n+ */\n+static void fd_fast_deep_nest_test(struct kunit *test)\n+{\n+\tint levels, len;\n+\tu8 *buf;\n+\n+\tbuf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);\n+\n+\tfor (levels = 1; levels \u003c= 24; levels++) {\n+\t\tlen = build_ipip_nest(buf, levels);\n+\t\tif (len \u003e FD_TEST_BUF_LEN)\n+\t\t\tbreak;\n+\t\tfd_fast_check_equiv(test, buf, htons(ETH_P_IP), len, 0);\n+\t}\n+\tfor (levels = 1; levels \u003c= 16; levels++) {\n+\t\tlen = build_gre_nest(buf, levels);\n+\t\tif (len \u003e FD_TEST_BUF_LEN)\n+\t\t\tbreak;\n+\t\tfd_fast_check_equiv(test, buf, htons(ETH_P_IP), len, 0);\n+\t}\n+}\n+\n+/* Non-linear skb: the fast path reads only the linear head and must\n+ * defer; the slow path pulls from the frag. Output must match.\n+ */\n+static void fd_fast_nonlinear_skb_test(struct kunit *test)\n+{\n+\tconst int linear = 8;\n+\tstruct sk_buff *skb;\n+\tstruct page *page;\n+\tu8 *buf;\n+\tint len;\n+\n+\tbuf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);\n+\tlen = build_ipv4_tcp(buf);\n+\n+\tskb = alloc_skb(NET_SKB_PAD + linear, GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, skb);\n+\tskb_reserve(skb, NET_SKB_PAD);\n+\tskb_put_data(skb, buf, linear);\n+\n+\tpage = alloc_page(GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, page);\n+\tmemcpy(page_address(page), buf + linear, len - linear);\n+\tskb_add_rx_frag(skb, 0, page, 0, len - linear, len - linear);\n+\n+\tskb-\u003eprotocol = htons(ETH_P_IP);\n+\tskb_reset_mac_header(skb);\n+\tskb_reset_network_header(skb);\n+\n+\tfd_fast_check_equiv_skb(test, skb);\n+\tkfree_skb(skb);\n+}\n+\n+/* An ineligible (custom) dissector: the fast path must never run,\n+ * so gates-on output equals gates-off for the whole corpus.\n+ */\n+static void fd_fast_ineligible_dissector_test(struct kunit *test)\n+{\n+\tstatic const struct flow_dissector_key keys[] = {\n+\t\t{ .key_id = FLOW_DISSECTOR_KEY_CONTROL,\n+\t\t  .offset = offsetof(struct flow_keys, control) },\n+\t\t{ .key_id = FLOW_DISSECTOR_KEY_BASIC,\n+\t\t  .offset = offsetof(struct flow_keys, basic) },\n+\t\t{ .key_id = FLOW_DISSECTOR_KEY_IPV4_ADDRS,\n+\t\t  .offset = offsetof(struct flow_keys, addrs.v4addrs) },\n+\t\t{ .key_id = FLOW_DISSECTOR_KEY_IPV6_ADDRS,\n+\t\t  .offset = offsetof(struct flow_keys, addrs.v6addrs) },\n+\t\t{ .key_id = FLOW_DISSECTOR_KEY_PORTS,\n+\t\t  .offset = offsetof(struct flow_keys, ports) },\n+\t\t{ .key_id = FLOW_DISSECTOR_KEY_ICMP,\n+\t\t  .offset = offsetof(struct flow_keys, icmp) },\n+\t};\n+\tstruct flow_dissector custom;\n+\tint i, len;\n+\tu8 *buf;\n+\n+\tskb_flow_dissector_init(\u0026custom, keys, ARRAY_SIZE(keys));\n+\n+\tbuf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(fd_fast_cases); i++) {\n+\t\tconst struct fd_fast_case *c = \u0026fd_fast_cases[i];\n+\n+\t\tlen = c-\u003ebuild(buf);\n+\t\tfd_check_one(test, \u0026custom, buf, c-\u003eproto, len, c-\u003eflags);\n+\t}\n+}\n+\n+/* skb-mode coverage for ipv6 / pppoe / mpls / gre. */\n+static void fd_fast_skb_shapes_test(struct kunit *test)\n+{\n+\tstatic const struct {\n+\t\tint (*build)(u8 *buf);\n+\t\t__be16 proto;\n+\t} cases[] = {\n+\t\t{ build_ipv6_tcp, cpu_to_be16(ETH_P_IPV6) },\n+\t\t{ build_pppoe_ipv4_tcp, cpu_to_be16(ETH_P_PPP_SES) },\n+\t\t{ build_mpls_ipv4, cpu_to_be16(ETH_P_MPLS_UC) },\n+\t\t{ build_gre_ipv4, cpu_to_be16(ETH_P_IP) },\n+\t};\n+\tint i;\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(cases); i++) {\n+\t\tstruct sk_buff *skb;\n+\n+\t\tskb = fd_fast_build_skb(test, cases[i].build, cases[i].proto);\n+\t\tfd_fast_check_equiv_skb(test, skb);\n+\t\tkfree_skb(skb);\n+\t}\n+}\n+\n+/* Seeded, reproducible fuzzer: mutate corpus packets and lengths,\n+ * assert equivalence each iteration -- the guard for divergences the\n+ * hand-written corpus does not name.\n+ */\n+static void fd_fast_fuzz_test(struct kunit *test)\n+{\n+\tstruct rnd_state rnd;\n+\tu8 *buf;\n+\tint i;\n+\n+\tbuf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);\n+\tprandom_seed_state(\u0026rnd, 0x1a2b3c4d5e6f7788ULL);\n+\n+\tfor (i = 0; i \u003c FD_FUZZ_ITERS; i++) {\n+\t\tconst struct fd_fast_case *c;\n+\t\tunsigned int flags;\n+\t\tint len, j, nmut;\n+\n+\t\tc = \u0026fd_fast_cases[prandom_u32_state(\u0026rnd) %\n+\t\t\t\t   ARRAY_SIZE(fd_fast_cases)];\n+\t\tlen = c-\u003ebuild(buf);\n+\n+\t\t/* Mutate a handful of header bytes to random values. */\n+\t\tnmut = prandom_u32_state(\u0026rnd) % (len + 1);\n+\t\tfor (j = 0; j \u003c nmut; j++)\n+\t\t\tbuf[prandom_u32_state(\u0026rnd) % len] =\n+\t\t\t\tprandom_u32_state(\u0026rnd);\n+\n+\t\t/* Random truncation and random 1st-frag flag. */\n+\t\tlen = prandom_u32_state(\u0026rnd) % (len + 1);\n+\t\tflags = (prandom_u32_state(\u0026rnd) \u0026 1) ?\n+\t\t\tFLOW_DISSECTOR_F_PARSE_1ST_FRAG : 0;\n+\n+\t\tfd_fast_check_equiv(test, buf, c-\u003eproto, len, flags);\n+\t}\n+}\n+\n+/* Gates off: the fast path must never run (counters are the\n+ * observable). Positive controls: an eligible shape must count with\n+ * the gates on.\n+ */\n+static void fd_fast_gates_off_test(struct kunit *test)\n+{\n+\tstruct flow_keys keys;\n+\tu64 before;\n+\tint i, len;\n+\tu8 *buf;\n+\n+\tbuf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);\n+\n+\tfd_fast_gates_set(false);\n+\tbefore = flow_dissector_fast_hits_kunit();\n+\tfor (i = 0; i \u003c ARRAY_SIZE(fd_fast_cases); i++) {\n+\t\tlen = fd_fast_cases[i].build(buf);\n+\t\tmemset(\u0026keys, 0, sizeof(keys));\n+\t\t__skb_flow_dissect(\u0026init_net, NULL, \u0026flow_keys_dissector,\n+\t\t\t\t   \u0026keys, buf, fd_fast_cases[i].proto, 0,\n+\t\t\t\t   len, fd_fast_cases[i].flags);\n+\t}\n+\tKUNIT_EXPECT_EQ(test, flow_dissector_fast_hits_kunit(), before);\n+\n+\tfd_fast_gates_set(true);\n+\tlen = build_ipv4_tcp(buf);\n+\tmemset(\u0026keys, 0, sizeof(keys));\n+\t__skb_flow_dissect(\u0026init_net, NULL, \u0026flow_keys_dissector, \u0026keys,\n+\t\t\t   buf, htons(ETH_P_IP), 0, len, 0);\n+\tKUNIT_EXPECT_GT(test, flow_dissector_fast_hits_kunit(), before);\n+\n+\t/* Flagship consumer shape: skb_get_hash() passes STOP_AT_FLOW_LABEL;\n+\t * the fast path must hit for it.\n+\t */\n+\tbefore = flow_dissector_fast_hits_kunit();\n+\tmemset(\u0026keys, 0, sizeof(keys));\n+\t__skb_flow_dissect(\u0026init_net, NULL, \u0026flow_keys_dissector, \u0026keys,\n+\t\t\t   buf, htons(ETH_P_IP), 0, len,\n+\t\t\t   FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL);\n+\tfd_fast_gates_set(false);\n+\tKUNIT_EXPECT_GT(test, flow_dissector_fast_hits_kunit(), before);\n+}\n+\n+static void fd_all_gates_off(void)\n+{\n+\tfd_fast_gates_set(false);\n+}\n+\n+static int fd_fast_suite_init(struct kunit_suite *suite)\n+{\n+\tfd_all_gates_off();\n+\treturn 0;\n+}\n+\n+static void fd_fast_suite_exit(struct kunit_suite *suite)\n+{\n+\tfd_all_gates_off();\n+}\n+\n+static struct kunit_case fd_fast_test_cases[] = {\n+\tKUNIT_CASE_PARAM(fd_fast_equiv_test, fd_fast_gen_params),\n+\tKUNIT_CASE(fd_fast_truncation_test),\n+\tKUNIT_CASE(fd_fast_deep_nest_test),\n+\tKUNIT_CASE(fd_fast_nonlinear_skb_test),\n+\tKUNIT_CASE(fd_fast_ineligible_dissector_test),\n+\tKUNIT_CASE(fd_fast_skb_plain_test),\n+\tKUNIT_CASE(fd_fast_skb_hwaccel_vlan_test),\n+\tKUNIT_CASE(fd_fast_skb_hwaccel_vlan_qinq_test),\n+\tKUNIT_CASE(fd_fast_skb_shapes_test),\n+\tKUNIT_CASE(fd_fast_fuzz_test),\n+\tKUNIT_CASE(fd_fast_gates_off_test),\n+\t{}\n+};\n+\n+static struct kunit_suite fd_fast_suite = {\n+\t.name = \"flow_dissector_fastpath\",\n+\t.suite_init = fd_fast_suite_init,\n+\t.suite_exit = fd_fast_suite_exit,\n+\t.test_cases = fd_fast_test_cases,\n+};\n+\n+kunit_test_suite(fd_fast_suite);\n+\n+MODULE_DESCRIPTION(\"KUnit fast/slow equivalence tests for the flow dissector\");\n+MODULE_LICENSE(\"GPL\");\n"
}

2/1 2026/07/16 04:38 agent patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [
    "flow_dissect_fast",
    "flow_dissect_fast_ipv4",
    "flow_dissect_fast_ipv6",
    "flow_dissect_fast_vlan",
    "flow_dissect_fast_pppoe",
    "flow_dissect_fast_mpls",
    "flow_dissect_fast_ipip_inner",
    "flow_dissect_fast_gre_inner",
    "proc_set_vlan_key",
    "proc_set_qinq_key"
  ],
  "Reasoning": "The patch introduces opt-in fast paths for the network flow dissector. This is reachable core network logic that processes untrusted packet data, making it a prime target for fuzzing to ensure memory safety and correctness of the new parsing logic.",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer.
Your job is to review a provided patch series and determine
if it makes functional changes to the kernel that should be fuzzed.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on your internal knowledge of the kernel. You must actively
use your code access tools to examine the actual source code and confirm any assumptions.

Return WorthFuzzing=false if the patch only contains:
- Modifications to Documentation/, Kconfig files, or code comments.
- Purely decorative changes, such as logging (e.g., pr_err, printk) or tracepoints.
- Changes to numeric constants or macros that do not functionally alter execution flow.
- Code paths that are impossible to reach in virtualized environments like GCE or QEMU,
even when utilizing software-emulated hardware (e.g., usb gadget, mac80211_hwsim).

If it modifies reachable core kernel logic, drivers, or architectures, use your code search
tools to verify the code can be executed, then return WorthFuzzing=true.

When returning WorthFuzzing=true, you MUST ALSO:
1. Extract any specific kernel functions that should be heavily fuzzed into FocusSymbols.
   Avoid listing generic hot-path functions to prevent skewed test distributions.
2. Identify any specific CONFIG_ options required to properly test this new/modified feature.
   Go and look into the Kconfig files and check for ifdefs around the code, do not make assumptions.
   Do not list too generic configs (we already have them enabled). Only list those that
   specifically cover the modified code. List them in the EnableConfigs output array,
   and DO NOT add a 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
For your convenience, here is the diff of the changes:
commit fa4cb94e8670a4e763d6397cd01731732e29dc14
Author: syz-cluster <triage@syzkaller.com>
Date:   Thu Jul 16 04:38:04 2026 +0000

    syz-cluster: applied patch under review

diff --git a/Documentation/admin-guide/sysctl/net.rst b/Documentation/admin-guide/sysctl/net.rst
index e586e17fc7a582..3b55b2528ba2ed 100644
--- a/Documentation/admin-guide/sysctl/net.rst
+++ b/Documentation/admin-guide/sysctl/net.rst
@@ -460,7 +460,183 @@ historical importance.
 
 Default: 0
 
-2. /proc/sys/net/unix - Parameters for Unix domain sockets
+2. /proc/sys/net/flow_dissector - Flow dissector fast-path per-shape sysctls
+---------------------------------------------------------------------------
+
+The flow dissector is invoked on every packet that needs a flow hash
+(RPS, RFS, ECMP, sch_cake, cls_flower, ...). For common shapes
+(Eth+IPv4/IPv6+TCP/UDP, plus per-shape extensions for VLAN/QinQ,
+PPPoE, MPLS, IP-in-IP and GRE added by this series), an opt-in
+fast-path bypasses the slow-path graph walk and writes
+``struct flow_keys`` directly. Each shape is gated by its own static
+key + sysctl so operators enable only what their deployment uses.
+
+All defaults are 0 (off). Flipping any of these on takes effect
+immediately; no kernel rebuild needed.
+
+eth_ip
+~~~~~~
+
+Eth + IPv4 (IHL=5, no fragmentation) + TCP/UDP, and Eth + IPv6 (no
+extension headers) + TCP/UDP. Output is byte-identical to the slow
+path on the eligible shape; non-matching packets fall through to the
+slow path unchanged. The dispatcher costs one not-taken JMP per call
+when this is 0.
+
+Default: 0
+
+vlan
+~~~~
+
+Single 802.1Q or 802.1AD tagged frames over Eth + IPv4/IPv6 +
+TCP/UDP. Handles both the hardware-stripped form (tag in skb
+metadata, inner ethertype in skb->protocol) and the in-band form
+(4-byte vlan_hdr at data + nhoff). Writes FLOW_DISSECTOR_KEY_VLAN
+and bumps FLOW_DISSECTOR_KEY_NUM_OF_VLANS when those keys are
+requested by the dissector. Byte-identical with the slow path for
+the eligible shape; defers on any miss (QinQ defers; see the qinq
+sysctl).
+
+Default: 0
+
+qinq
+~~~~
+
+Lifts the vlan fast-path's depth limit from 1 to 2 so two stacked
+802.1AD / 802.1Q tags (canonical QinQ S-tag + C-tag, or two stacked
+802.1Q tags) are also fast-pathed. Outer tag is written to
+FLOW_DISSECTOR_KEY_VLAN, inner to FLOW_DISSECTOR_KEY_CVLAN, mirroring
+the slow-path's MAX → VLAN → CVLAN state machine. Byte-identical
+with the slow path for the eligible shape.
+
+Auto-toggle: writing qinq=1 also enables vlan (QinQ extends VLAN;
+the depth-0 entry of the helper is gated by the vlan key). Turning
+vlan off (writing 0) also clears qinq (depth-2 cannot fire when
+the outer entry is off).
+
+Default: 0
+
+pppoe
+~~~~~
+
+PPPoE session frames (RFC 2516, EtherType ``ETH_P_PPP_SES`` 0x8864)
+carrying IPv4 or IPv6 inside PPP. The fast-path strips the 6-byte
+PPPoE session header + 2-byte PPP protocol field, writes
+FLOW_DISSECTOR_KEY_PPPOE (session_id, ppp_proto, type) when the
+dissector requests it, and tail-calls into the eth_ip fast-path for
+the inner IPv4 / IPv6 + TCP/UDP. Byte-identical with the slow path
+for the eligible shape.
+
+Defers to slow path for: PPP_MPLS_UC / PPP_MPLS_MC (until an MPLS
+fast-path lands), PFC-compressed PPP protocol fields, LCP/IPCP/etc.
+control frames, and any malformed PPPoE header (ver != 1, type != 1,
+code != 0).
+
+Default: 0
+
+mpls
+~~~~
+
+Single-label MPLS frames (EtherType ``ETH_P_MPLS_UC`` 0x8847 or
+``ETH_P_MPLS_MC`` 0x8848 with bottom-of-stack bit set on the first
+label). The fast-path reads the 4-byte label entry, extracts
+label / TC / TTL / BoS, and writes them to FLOW_DISSECTOR_KEY_MPLS
+lse[0] when requested. Byte-identical with the slow path's
+__skb_flow_dissect_mpls() for lse_index=0, bos=1: the slow path
+returns OUT_GOOD on BoS without descending into the inner packet
+(MPLS hashing is on the label stack, not inner 5-tuple), so this
+fast-path does the same.
+
+Multi-label stacks (BoS=0 on the first label) defer to slow path —
+extending to depth-2 or more is a follow-up, mirroring the
+vlan -> qinq staging used earlier in this series.
+
+Default: 0
+
+ipip
+~~~~
+
+IPv4-in-IPv4 (``IPPROTO_IPIP`` 4), IPv6-in-IPv4 (``IPPROTO_IPV6`` 41
+inside an IPv4 outer), IPv4-in-IPv6 and IPv6-in-IPv6 tunnels. When
+the outer IP fast-path notices the outer protocol/nexthdr is one of
+these and this gate is on, it skips the outer header and tail-calls
+into the inner IPv4 / IPv6 fast-path. The flow_keys ends up with the
+inner 5-tuple (matching the slow path's behaviour, where the inner
+parse overwrites the outer addrs/basic), plus
+FLOW_DIS_ENCAPSULATION set on key_control->flags.
+
+Byte-identical with the slow path's IPPROTO_IPIP / IPPROTO_IPV6
+switch cases for the eligible shape. Defers on any miss — including
+fragmented outer, unusual outer IHL, or unsupported inner shapes
+that the inner IP fast-path itself would defer.
+
+Default: 0
+
+gre
+~~~
+
+GRE-encapsulated inner IP (``IPPROTO_GRE`` 47). The fast-path
+mirrors the slow path's __skb_flow_dissect_gre() descent for the
+common subset:
+
+- GRE version 0 (the v1 PPTP variant defers to slow path)
+- All GRE flags clear (no GRE_CSUM, GRE_KEY, GRE_SEQ, GRE_ROUTING —
+  i.e. plain 4-byte GRE base header)
+- protocol field is ``ETH_P_IP`` 0x0800 or ``ETH_P_IPV6`` 0x86DD
+  (no Transparent Ethernet Bridging, no PPP-over-GRE, no MPLS-
+  over-GRE)
+
+In that subset, slow path also descends to inner IP and stamps
+``key_control->flags |= FLOW_DIS_ENCAPSULATION``; the fast-path
+produces the same output.
+
+GRE-with-KEY (common in MPLS-over-GRE deployments and some cloud
+overlays) is a follow-up patch — same descent shape with an
+additional 4-byte key field read and a write to
+``FLOW_DISSECTOR_KEY_GRE_KEYID``.
+
+Default: 0
+
+The ``/proc/net/flow_dissector_stats`` observability file
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Read-only. Reports, per byte-identical shape, the number of packets the
+slow path handled (``occurrences``), the number the fast body handled
+(``fast_hits``), the resulting eligible fraction, and the current gate
+state, plus a total dissect count. Because the fast path returns before
+the slow-path classification, exactly one of the two counters is
+incremented per shaped packet depending on gate state, so
+``(occurrences + fast_hits) / dissects`` is a gate-invariant measure of
+how much traffic each shape's fast body would handle -- the signal an
+operator uses to decide whether a gate is worth enabling. The slow-path
+counts sit at protocol recognition points, a superset of fast-path
+eligibility (a VLAN+ARP frame counts as vlan), so the eligible fraction
+is an upper bound; the exact hit rate once a gate is on is
+``fast_hits / (occurrences + fast_hits)``. The counters
+are per-cpu and summed on read; the per-packet cost is one increment on
+the already-hot classification path.
+
+An example snapshot, from a host that mostly sees plain Eth + IP traffic
+with some VLAN, before any gate has been enabled::
+
+  # cat /proc/net/flow_dissector_stats
+  shape         occurrences        fast_hits  eligible%  gate
+  eth_ip            1866909                0      75.71   off
+  vlan               598847                0      24.28   off
+  qinq                    0                0       0.00   off
+  pppoe                   0                0       0.00   off
+  mpls                    0                0       0.00   off
+  ipip                    0                0       0.00   off
+  gre                     0                0       0.00   off
+  dissects: 2465765
+
+Read top-down: 76% of dissects are plain Eth + IP and 24% are
+VLAN-tagged, so ``eth_ip`` and ``vlan`` are the shapes worth enabling on
+this host; the other shapes are absent. Every gate is still off, so all
+the traffic sits under ``occurrences``; enabling a gate moves that
+shape's packets to ``fast_hits``.
+
+3. /proc/sys/net/unix - Parameters for Unix domain sockets
 ----------------------------------------------------------
 
 There is only one file in this directory.
diff --git a/Documentation/bpf/index.rst b/Documentation/bpf/index.rst
index 0d5c6f6592667a..6e26731fa06fd7 100644
--- a/Documentation/bpf/index.rst
+++ b/Documentation/bpf/index.rst
@@ -23,6 +23,7 @@ that goes into great technical depth about the BPF Architecture.
    cpumasks
    fs_kfuncs
    programs
+   prog_flow_dissector
    maps
    bpf_prog_run
    classic_vs_extended.rst
diff --git a/Documentation/bpf/prog_flow_dissector.rst b/Documentation/bpf/prog_flow_dissector.rst
index f24270b8b0343c..f4c4648461ca83 100644
--- a/Documentation/bpf/prog_flow_dissector.rst
+++ b/Documentation/bpf/prog_flow_dissector.rst
@@ -9,6 +9,8 @@ Overview
 
 Flow dissector is a routine that parses metadata out of the packets. It's
 used in the various places in the networking subsystem (RFS, flow hash, etc).
+See :doc:`/networking/flow_dissector` for an overview of the flow dissector
+and the built-in C implementation this program type overrides.
 
 BPF flow dissector is an attempt to reimplement C-based flow dissector logic
 in BPF to gain all the benefits of BPF verifier (namely, limits on the
diff --git a/Documentation/networking/flow_dissector.rst b/Documentation/networking/flow_dissector.rst
new file mode 100644
index 00000000000000..014f6d124b4fc2
--- /dev/null
+++ b/Documentation/networking/flow_dissector.rst
@@ -0,0 +1,133 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+==============
+Flow Dissector
+==============
+
+Overview
+========
+
+The flow dissector parses a packet's headers into a ``struct flow_keys``: the
+addresses, ports, and other fields that identify the flow the packet belongs
+to. Its entry point is ``__skb_flow_dissect()`` in
+``net/core/flow_dissector.c``.
+
+The dissected keys feed ``skb->hash`` (via ``flow_hash_from_keys()``), which is
+the canonical flow identity consumed all over the stack, including:
+
+* receive-side steering: RSS, RPS, RFS and accelerated RFS (aRFS);
+* transmit-side spreading: ECMP / multipath route selection and bonding / LAG
+  ``xmit_hash_policy``;
+* classification and offload: tc-flower.
+
+A single dissection therefore feeds every one of these, so the dissector sits
+on a hot path in most networking workloads.
+
+Two standard dissectors are built in: ``flow_keys_dissector`` (the general one)
+and ``flow_keys_dissector_symmetric`` (same source and destination hashed
+symmetrically). In addition, subsystems such as tc-flower build **custom**
+dissector instances at run time that request only the keys they need. A custom
+instance carries its own ``used_keys`` bitmask and per-key offset table, so its
+field accesses are resolved dynamically at each dissect.
+
+struct flow_keys
+================
+
+``struct flow_keys`` (see ``include/net/flow_dissector.h``) collects the
+dissected metadata. Its main members are:
+
+* ``control`` -- address type and control flags (for example
+  ``FLOW_DIS_ENCAPSULATION`` when the keys came from inside a tunnel, and
+  ``FLOW_DIS_IS_FRAGMENT``);
+* ``basic`` -- L3 protocol (``n_proto``) and L4 protocol (``ip_proto``);
+* ``addrs`` -- source and destination addresses (IPv4 or IPv6);
+* ``ports`` -- source and destination ports;
+* ``vlan`` / ``cvlan`` -- 802.1Q / 802.1AD tags;
+* ``tags``, ``keyid``, ``icmp`` -- MPLS/flow-label tags, GRE/tunnel key, and
+  ICMP identifiers.
+
+The dissection path
+===================
+
+The built-in dissector is a generic protocol-graph parser: it walks the header
+chain in a loop, dispatching on the current L2/L3 ethertype and then the L4
+protocol, following encapsulation (IP-in-IP, GRE, ...) by re-entering the loop
+on the inner header. The number of headers it will descend through is bounded
+by ``MAX_FLOW_DISSECT_HDRS`` so that a crafted deeply nested packet cannot make
+it loop without limit.
+
+This generic parser is referred to below as the *slow path*: it is table- and
+loop-driven and handles every protocol the dissector knows about.
+
+The BPF flow dissector
+======================
+
+A per-network-namespace BPF program can be attached to replace the built-in
+dissector for the protocols it chooses to handle. When one is attached,
+``__skb_flow_dissect()`` runs it **first**; if the program returns a verdict
+other than ``BPF_FLOW_DISSECTOR_CONTINUE``, its result is used and the built-in
+dissector (including the fast paths below) is not run for that packet. A system
+running an attached BPF dissector therefore sees behaviour defined entirely by
+its program.
+
+See :doc:`/bpf/prog_flow_dissector` for the BPF program type, its API, and its
+reference implementation.
+
+Opt-in fast paths
+=================
+
+For the packet shapes that dominate real deployments, the built-in dissector
+also provides an opt-in, straight-line *fast path* that produces the same
+result as the slow-path graph walk with far fewer instructions. Restricting the
+fast path to the two standard dissectors turns their per-key offsets into
+compile-time constants, so the parse becomes branch-light straight-line code;
+the isolated per-dissect cost of the eligible shapes drops by roughly half,
+with the largest wins on in-order cores.
+
+Each shape has its own gate -- a ``static_branch`` exposed as a sysctl under
+``/proc/sys/net/flow_dissector/`` -- and **every gate is off by default**. When
+a gate is off, the only added cost is one not-taken branch per dissect, and the
+dissector's output is exactly what it was before. The fast path runs only
+*after* the BPF hook described above, so an attached BPF program always takes
+precedence.
+
+The fast paths are **byte-identical by contract**: for any packet, a fast path
+either writes exactly the ``flow_keys`` the slow path would have written, or it
+returns false and the slow path runs. There are only these two outcomes, and
+the equivalence is enforced in-tree by a KUnit test suite
+(``CONFIG_FLOW_DISSECTOR_KUNIT_TEST``). Enabling a byte-identical shape gate
+never changes any consumer's hash; it only makes the dissection cheaper.
+
+The eligible byte-identical shapes are plain Ethernet + IPv4/IPv6 + TCP/UDP,
+single and stacked VLAN (QinQ), PPPoE sessions, a single MPLS label, the
+IP-in-IP family, and plain GRE. The individual knobs are documented in
+:doc:`/admin-guide/sysctl/net` under ``/proc/sys/net/flow_dissector``.
+
+When to enable
+==============
+
+Turning a byte-identical shape gate on is worthwhile when enough traffic matches
+that shape to repay the small cost a non-matching packet pays while the gate is
+on. Concretely, if a matching packet saves ``S`` and a non-matching packet costs
+``C`` (both measured per shape and per micro-architecture), enabling the gate is
+net-positive once the fraction of traffic matching the shape exceeds the
+break-even ``p_be = C / (S + C)``.
+
+That fraction is observable: the read-only file
+``/proc/net/flow_dissector_stats`` reports, per shape, how many packets the slow
+path handled, how many the fast body handled, and the resulting eligible
+fraction, so ``(occurrences + fast_hits) / dissects`` is a gate-invariant
+measure of how much traffic each shape would accelerate.
+
+A separate RFC proposes an optional ``auto`` mode built on these counters: the
+kernel would sample them over a packet-count window and flip the
+byte-identical gates itself, with hysteresis and a flip-rate cap, so the
+operator does not have to tune each shape by hand. That controller is not part
+of this series.
+
+References
+==========
+
+* :doc:`/admin-guide/sysctl/net` -- the ``/proc/sys/net/flow_dissector/``
+  per-shape knob reference and the ``/proc/net/flow_dissector_stats`` file.
+* :doc:`/bpf/prog_flow_dissector` -- the BPF flow dissector program type.
diff --git a/Documentation/networking/index.rst b/Documentation/networking/index.rst
index 44a422ad3b0553..65368050ebab69 100644
--- a/Documentation/networking/index.rst
+++ b/Documentation/networking/index.rst
@@ -52,6 +52,7 @@ Contents:
    eql
    fib_trie
    filter
+   flow_dissector
    generic-hdlc
    generic_netlink
    ../netlink/specs/index
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 22eda1d54a0e84..6448c59dc80784 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1588,6 +1588,7 @@ void skb_flow_dissector_init(struct flow_dissector *flow_dissector,
 			     unsigned int key_count);
 
 struct bpf_flow_dissector;
+extern struct static_key_false netns_bpf_flow_dissector_enabled;
 u32 bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,
 		     __be16 proto, int nhoff, int hlen, unsigned int flags);
 
diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h
index ced79dc8e8560e..b92aef8039f8de 100644
--- a/include/net/flow_dissector.h
+++ b/include/net/flow_dissector.h
@@ -425,6 +425,40 @@ __be32 flow_get_u32_dst(const struct flow_keys *flow);
 extern struct flow_dissector flow_keys_dissector;
 extern struct flow_dissector flow_keys_basic_dissector;
 
+/* Per-shape fast-path static-branch keys, toggled via
+ * /proc/sys/net/flow_dissector/<shape>. All default off.
+ */
+extern struct static_key_false flow_dissector_eth_ip_key;
+extern struct static_key_false flow_dissector_vlan_key;
+extern struct static_key_false flow_dissector_qinq_key;
+extern struct static_key_false flow_dissector_pppoe_key;
+extern struct static_key_false flow_dissector_mpls_key;
+extern struct static_key_false flow_dissector_ipip_key;
+extern struct static_key_false flow_dissector_gre_key;
+
+/* Per-shape counters for /proc/net/flow_dissector_stats.
+ * occurrences[]: shape seen by the slow path (the eligible-fraction
+ * signal while its gate is off); fast_hits[]: fast path ran.
+ * Byte-identical shapes only; the behaviour-changing descents are
+ * never counted or auto-managed.
+ */
+enum flow_dissector_shape {
+	FLOW_DISSECTOR_SHAPE_ETH_IP,
+	FLOW_DISSECTOR_SHAPE_VLAN,
+	FLOW_DISSECTOR_SHAPE_QINQ,
+	FLOW_DISSECTOR_SHAPE_PPPOE,
+	FLOW_DISSECTOR_SHAPE_MPLS,
+	FLOW_DISSECTOR_SHAPE_IPIP,
+	FLOW_DISSECTOR_SHAPE_GRE,
+	FLOW_DISSECTOR_SHAPE__MAX,
+};
+
+#if IS_ENABLED(CONFIG_FLOW_DISSECTOR_KUNIT_TEST)
+/* Test-only accessors, defined in flow_dissector.c. */
+struct flow_dissector *flow_keys_dissector_symmetric_kunit(void);
+u64 flow_dissector_fast_hits_kunit(void);
+#endif
+
 /* struct flow_keys_digest:
  *
  * This structure is used to hold a digest of the full flow keys. This is a
diff --git a/kernel/bpf/net_namespace.c b/kernel/bpf/net_namespace.c
index 25f30f9edaefd3..0d48ea65697e56 100644
--- a/kernel/bpf/net_namespace.c
+++ b/kernel/bpf/net_namespace.c
@@ -28,6 +28,9 @@ DEFINE_MUTEX(netns_bpf_mutex);
 static void netns_bpf_attach_type_unneed(enum netns_bpf_attach_type type)
 {
 	switch (type) {
+	case NETNS_BPF_FLOW_DISSECTOR:
+		static_branch_dec(&netns_bpf_flow_dissector_enabled);
+		break;
 #ifdef CONFIG_INET
 	case NETNS_BPF_SK_LOOKUP:
 		static_branch_dec(&bpf_sk_lookup_enabled);
@@ -41,6 +44,9 @@ static void netns_bpf_attach_type_unneed(enum netns_bpf_attach_type type)
 static void netns_bpf_attach_type_need(enum netns_bpf_attach_type type)
 {
 	switch (type) {
+	case NETNS_BPF_FLOW_DISSECTOR:
+		static_branch_inc(&netns_bpf_flow_dissector_enabled);
+		break;
 #ifdef CONFIG_INET
 	case NETNS_BPF_SK_LOOKUP:
 		static_branch_inc(&bpf_sk_lookup_enabled);
@@ -352,6 +358,11 @@ int netns_bpf_prog_attach(const union bpf_attr *attr, struct bpf_prog *prog)
 	net->bpf.progs[type] = prog;
 	if (attached)
 		bpf_prog_put(attached);
+	else
+		/* Mark attach point as used on a fresh attach; a
+		 * replacement keeps the existing count.
+		 */
+		netns_bpf_attach_type_need(type);
 
 out_unlock:
 	mutex_unlock(&netns_bpf_mutex);
@@ -373,6 +384,8 @@ static int __netns_bpf_prog_detach(struct net *net,
 	attached = net->bpf.progs[type];
 	if (!attached || attached != old)
 		return -ENOENT;
+	/* Mark attach point as unused */
+	netns_bpf_attach_type_unneed(type);
 	netns_bpf_run_array_detach(net, type);
 	net->bpf.progs[type] = NULL;
 	bpf_prog_put(attached);
@@ -546,8 +559,10 @@ static void __net_exit netns_bpf_pernet_pre_exit(struct net *net)
 			net_link->net = NULL; /* auto-detach link */
 			netns_bpf_attach_type_unneed(type);
 		}
-		if (net->bpf.progs[type])
+		if (net->bpf.progs[type]) {
+			netns_bpf_attach_type_unneed(type);
 			bpf_prog_put(net->bpf.progs[type]);
+		}
 	}
 	mutex_unlock(&netns_bpf_mutex);
 }
diff --git a/net/Kconfig b/net/Kconfig
index e384773935515d..d0ce8fc344290c 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -540,4 +540,16 @@ config NET_TEST
 
 	  If unsure, say N.
 
+config FLOW_DISSECTOR_KUNIT_TEST
+	tristate "KUnit tests for flow dissector fast/slow path equivalence" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  KUnit tests asserting the flow dissector's opt-in per-shape
+	  fast paths produce byte-identical struct flow_keys output to
+	  the slow path for every corpus packet, with the gates on and
+	  off.
+
+	  If unsure, say N.
+
 endif   # if NET
diff --git a/net/core/Makefile b/net/core/Makefile
index b3fdcb4e355fa6..b27c69580d2ca0 100644
--- a/net/core/Makefile
+++ b/net/core/Makefile
@@ -46,6 +46,7 @@ obj-$(CONFIG_BPF_SYSCALL) += sock_map.o
 obj-$(CONFIG_BPF_SYSCALL) += bpf_sk_storage.o
 obj-$(CONFIG_OF)	+= of_net.o
 obj-$(CONFIG_NET_TEST) += net_test.o
+obj-$(CONFIG_FLOW_DISSECTOR_KUNIT_TEST) += flow_dissector_test.o
 obj-$(CONFIG_NET_DEVMEM) += devmem.o
 obj-$(CONFIG_DEBUG_NET) += lock_debug.o
 obj-$(CONFIG_FAIL_SKB_REALLOC) += skb_fault_injection.o
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 8aa4f9b4df8101..aaed4473c211e2 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -36,6 +36,92 @@
 #include <net/netfilter/nf_conntrack_labels.h>
 #endif
 #include <linux/bpf-netns.h>
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
+#include <linux/string_choices.h>
+#include <linux/math64.h>
+
+/* Per-shape fast-path gates, one static_branch per shape so operators
+ * enable only what their deployment carries. All default off.
+ */
+DEFINE_STATIC_KEY_FALSE(flow_dissector_eth_ip_key);
+EXPORT_SYMBOL(flow_dissector_eth_ip_key);
+DEFINE_STATIC_KEY_FALSE(flow_dissector_vlan_key);
+EXPORT_SYMBOL(flow_dissector_vlan_key);
+DEFINE_STATIC_KEY_FALSE(flow_dissector_qinq_key);
+EXPORT_SYMBOL(flow_dissector_qinq_key);
+DEFINE_STATIC_KEY_FALSE(flow_dissector_pppoe_key);
+EXPORT_SYMBOL(flow_dissector_pppoe_key);
+DEFINE_STATIC_KEY_FALSE(flow_dissector_mpls_key);
+EXPORT_SYMBOL(flow_dissector_mpls_key);
+DEFINE_STATIC_KEY_FALSE(flow_dissector_ipip_key);
+EXPORT_SYMBOL(flow_dissector_ipip_key);
+DEFINE_STATIC_KEY_FALSE(flow_dissector_gre_key);
+EXPORT_SYMBOL(flow_dissector_gre_key);
+
+/* Per-cpu, summed on read via /proc/net/flow_dissector_stats.
+ * occurrences[]: shape handled by the slow path (with the gate off,
+ * the shape's eligible-fraction signal); fast_hits[]: fast body ran;
+ * dissects: denominator.
+ */
+struct flow_dissector_stats {
+	u64 occurrences[FLOW_DISSECTOR_SHAPE__MAX];
+	u64 fast_hits[FLOW_DISSECTOR_SHAPE__MAX];
+	u64 dissects;
+};
+
+static DEFINE_PER_CPU(struct flow_dissector_stats, flow_dissector_pcpu_stats);
+
+static inline void flow_dissector_count_slow(enum flow_dissector_shape shape)
+{
+	this_cpu_inc(flow_dissector_pcpu_stats.occurrences[shape]);
+}
+
+static inline void flow_dissector_count_fast(enum flow_dissector_shape shape)
+{
+	this_cpu_inc(flow_dissector_pcpu_stats.fast_hits[shape]);
+}
+
+/* Counting map: eth_ip counts in the dispatcher (only when the leaf
+ * did not set ENCAP), vlan/qinq/pppoe/mpls in their helpers, ipip/gre
+ * in the inner-descent helpers. The slow path counts where it
+ * recognises each shape, gate on or off.
+ */
+
+/* IPv4 version/IHL byte of an option-less header: version 4, IHL 5. */
+#define FLOW_DIS_IPV4_VIHL_NOOPT	0x45
+
+/* @num_hdrs: protocol headers consumed so far (Ethernet = 1, each VLAN
+ * tag, each outer IP header). Tunnel descents increment it and defer
+ * past MAX_FLOW_DISSECT_HDRS, so both paths stop at the same depth.
+ */
+static bool flow_dissect_fast_ipv4(const struct sk_buff *skb,
+				   struct flow_dissector *flow_dissector,
+				   void *target_container,
+				   const void *data,
+				   int nhoff, int hlen, int num_hdrs);
+static bool flow_dissect_fast_ipv6(const struct sk_buff *skb,
+				   struct flow_dissector *flow_dissector,
+				   void *target_container,
+				   const void *data,
+				   int nhoff, int hlen, int num_hdrs);
+static bool flow_dissect_fast_ipip_inner(const struct sk_buff *skb,
+					 struct flow_dissector *flow_dissector,
+					 void *target_container,
+					 const void *data,
+					 __be16 inner_eth_proto,
+					 int inner_nhoff, int hlen, int num_hdrs);
+static bool flow_dissect_fast_gre_inner(const struct sk_buff *skb,
+					struct flow_dissector *flow_dissector,
+					void *target_container,
+					const void *data,
+					int nhoff, int hlen, int num_hdrs);
+
+/* One of the two dissectors the fast-path eligibility check admits;
+ * defined here so flow_dissect_fast() below can reference it (its keys
+ * and init live near the bottom of the file).
+ */
+static struct flow_dissector flow_keys_dissector_symmetric __read_mostly;
 
 static void dissector_set_key(struct flow_dissector *flow_dissector,
 			      enum flow_dissector_key_id key_id)
@@ -73,6 +159,14 @@ void skb_flow_dissector_init(struct flow_dissector *flow_dissector,
 }
 EXPORT_SYMBOL(skb_flow_dissector_init);
 
+/* Enabled while any netns has a BPF flow dissector program attached;
+ * lets __skb_flow_dissect() skip the program lookup entirely in the
+ * common no-program case. Maintained by the netns-BPF attach/detach
+ * paths in kernel/bpf/net_namespace.c.
+ */
+DEFINE_STATIC_KEY_FALSE(netns_bpf_flow_dissector_enabled);
+EXPORT_SYMBOL(netns_bpf_flow_dissector_enabled);
+
 #ifdef CONFIG_BPF_SYSCALL
 int flow_dissector_bpf_prog_attach_check(struct net *net,
 					 struct bpf_prog *prog)
@@ -1035,6 +1129,688 @@ static bool is_pppoe_ses_hdr_valid(const struct pppoe_hdr *hdr)
 	return hdr->ver == 1 && hdr->type == 1 && hdr->code == 0;
 }
 
+/* The IPv4 fast-path assumes a 20-byte IPv4 header (IHL == 5). The
+ * runtime IHL check below is the dynamic invariant; this static
+ * assertion is the compile-time one, in the unlikely case struct
+ * iphdr ever grows.
+ */
+static_assert(sizeof(struct iphdr) == 20);
+
+/* Straight-line eth + IPv4 (IHL=5, not fragmented) + TCP|UDP. Returns
+ * true when @target_container has been filled byte-identically to the
+ * slow path; false on any miss (caller falls back to the slow path).
+ */
+static bool flow_dissect_fast_ipv4(const struct sk_buff *skb,
+				   struct flow_dissector *flow_dissector,
+				   void *target_container,
+				   const void *data,
+				   int nhoff, int hlen, int num_hdrs)
+{
+	struct flow_dissector_key_control *key_control;
+	struct flow_dissector_key_addrs *key_addrs;
+	struct flow_dissector_key_basic *key_basic;
+	struct flow_dissector_key_ports *key_ports;
+	const struct iphdr *iph;
+	int thoff;
+
+	if (unlikely(hlen - nhoff < (int)sizeof(*iph) + 4))
+		return false;
+
+	iph = (const struct iphdr *)((const u8 *)data + nhoff);
+
+	if (unlikely(*(const u8 *)iph != FLOW_DIS_IPV4_VIHL_NOOPT))
+		return false;
+
+	if (unlikely(iph->frag_off & htons(IP_MF | IP_OFFSET)))
+		return false;
+
+	if (unlikely(iph->protocol != IPPROTO_TCP &&
+		     iph->protocol != IPPROTO_UDP)) {
+		/* IPIP / IPv6-in-IPv4 outer: defer to the inner fast-path and
+		 * stamp ENCAP. Outer addrs are not written -- the inner pass
+		 * overwrites them, as in the slow path.
+		 */
+		if (static_branch_unlikely(&flow_dissector_ipip_key)) {
+			if (iph->protocol == IPPROTO_IPIP)
+				return flow_dissect_fast_ipip_inner(skb,
+						flow_dissector, target_container,
+						data, htons(ETH_P_IP),
+						nhoff + (int)sizeof(*iph), hlen, num_hdrs);
+			if (iph->protocol == IPPROTO_IPV6)
+				return flow_dissect_fast_ipip_inner(skb,
+						flow_dissector, target_container,
+						data, htons(ETH_P_IPV6),
+						nhoff + (int)sizeof(*iph), hlen, num_hdrs);
+		}
+		if (static_branch_unlikely(&flow_dissector_gre_key) &&
+		    iph->protocol == IPPROTO_GRE)
+			return flow_dissect_fast_gre_inner(skb, flow_dissector,
+					target_container, data,
+					nhoff + (int)sizeof(*iph), hlen, num_hdrs);
+		return false;
+	}
+
+	thoff = nhoff + (int)sizeof(*iph);
+
+	if (dissector_uses_key(flow_dissector,
+			       FLOW_DISSECTOR_KEY_CONTROL)) {
+		key_control = skb_flow_dissector_target(flow_dissector,
+							FLOW_DISSECTOR_KEY_CONTROL,
+							target_container);
+		key_control->addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
+		key_control->thoff = min_t(u16, thoff,
+					   skb ? skb->len : hlen);
+		key_control->flags = 0;
+	}
+	if (dissector_uses_key(flow_dissector,
+			       FLOW_DISSECTOR_KEY_BASIC)) {
+		key_basic = skb_flow_dissector_target(flow_dissector,
+						      FLOW_DISSECTOR_KEY_BASIC,
+						      target_container);
+		key_basic->n_proto = htons(ETH_P_IP);
+		key_basic->ip_proto = iph->protocol;
+	}
+	if (dissector_uses_key(flow_dissector,
+			       FLOW_DISSECTOR_KEY_IPV4_ADDRS)) {
+		key_addrs = skb_flow_dissector_target(flow_dissector,
+						      FLOW_DISSECTOR_KEY_IPV4_ADDRS,
+						      target_container);
+		memcpy(&key_addrs->v4addrs.src, &iph->saddr,
+		       sizeof(key_addrs->v4addrs.src));
+		memcpy(&key_addrs->v4addrs.dst, &iph->daddr,
+		       sizeof(key_addrs->v4addrs.dst));
+	}
+	if (dissector_uses_key(flow_dissector,
+			       FLOW_DISSECTOR_KEY_PORTS)) {
+		const __be32 *ports = (const __be32 *)
+			((const u8 *)data + thoff);
+
+		key_ports = skb_flow_dissector_target(flow_dissector,
+						      FLOW_DISSECTOR_KEY_PORTS,
+						      target_container);
+		key_ports->ports = *ports;
+	}
+
+	return true;
+}
+
+/* Same as flow_dissect_fast_ipv4 but for a fixed 40-byte IPv6 header
+ * (no extension headers). The nexthdr check below holds the run-time
+ * invariant; the static_assert holds the compile-time one.
+ */
+static_assert(sizeof(struct ipv6hdr) == 40);
+
+static bool flow_dissect_fast_ipv6(const struct sk_buff *skb,
+				   struct flow_dissector *flow_dissector,
+				   void *target_container,
+				   const void *data,
+				   int nhoff, int hlen, int num_hdrs)
+{
+	struct flow_dissector_key_control *key_control;
+	struct flow_dissector_key_addrs *key_addrs;
+	struct flow_dissector_key_basic *key_basic;
+	struct flow_dissector_key_ports *key_ports;
+	const struct ipv6hdr *iph;
+	int thoff;
+
+	if (unlikely(hlen - nhoff < (int)sizeof(*iph) + 4))
+		return false;
+
+	iph = (const struct ipv6hdr *)((const u8 *)data + nhoff);
+
+	if (unlikely((*(const u8 *)iph >> 4) != 6))
+		return false;
+
+	/* Any non-zero flow label defers, checked before everything else
+	 * (including the tunnel descents below). Callers passing
+	 * FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL (skb_get_hash() -- so
+	 * RPS/RFS, fq, cake) make the slow path stop at a non-zero label
+	 * even on a tunnel outer, and dissectors requesting the label key
+	 * write it; both diverge from the plain parse. Deferring on the
+	 * label itself covers every combination without threading flags
+	 * into the helpers, and zero-label IPv6 (the overwhelmingly
+	 * common case) stays on the fast path.
+	 */
+	if (unlikely((iph->flow_lbl[0] & 0x0f) |
+		     iph->flow_lbl[1] | iph->flow_lbl[2]))
+		return false;
+
+	if (unlikely(iph->nexthdr != IPPROTO_TCP &&
+		     iph->nexthdr != IPPROTO_UDP)) {
+		/* IPIP / IPV6-in-IPv6 tunnel outer: same pattern as the
+		 * IPv4 helper. The nexthdr_IPIP / nexthdr_IPV6 cases
+		 * defer to the inner IP fast-path and stamp ENCAP.
+		 */
+		bool ipip = static_branch_unlikely(&flow_dissector_ipip_key) &&
+			    (iph->nexthdr == IPPROTO_IPIP ||
+			     iph->nexthdr == IPPROTO_IPV6);
+		bool gre = static_branch_unlikely(&flow_dissector_gre_key) &&
+			   iph->nexthdr == IPPROTO_GRE;
+
+		if (!ipip && !gre)
+			return false;
+
+		/* Mirror the slow path's outer-IPv6 writes before the
+		 * descent. The slow path fills v6addrs for the outer
+		 * header and the inner pass then overwrites only what
+		 * it uses — an inner IPv4 leaves the tail of the addrs
+		 * union holding outer-v6 bytes. Byte-identical means
+		 * reproducing exactly that, residue included. (The
+		 * outer flow label is always zero here — a non-zero
+		 * label deferred above — so there is no label residue.)
+		 */
+		if (dissector_uses_key(flow_dissector,
+				       FLOW_DISSECTOR_KEY_IPV6_ADDRS)) {
+			key_addrs = skb_flow_dissector_target(flow_dissector,
+							      FLOW_DISSECTOR_KEY_IPV6_ADDRS,
+							      target_container);
+			memcpy(&key_addrs->v6addrs.src, &iph->saddr,
+			       sizeof(key_addrs->v6addrs.src));
+			memcpy(&key_addrs->v6addrs.dst, &iph->daddr,
+			       sizeof(key_addrs->v6addrs.dst));
+			key_control = skb_flow_dissector_target(flow_dissector,
+								FLOW_DISSECTOR_KEY_CONTROL,
+								target_container);
+			key_control->addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
+		}
+
+		if (ipip)
+			return flow_dissect_fast_ipip_inner(skb,
+					flow_dissector, target_container,
+					data,
+					iph->nexthdr == IPPROTO_IPIP ?
+					htons(ETH_P_IP) : htons(ETH_P_IPV6),
+					nhoff + (int)sizeof(*iph), hlen, num_hdrs);
+		return flow_dissect_fast_gre_inner(skb, flow_dissector,
+				target_container, data,
+				nhoff + (int)sizeof(*iph), hlen, num_hdrs);
+	}
+
+	thoff = nhoff + (int)sizeof(*iph);
+
+	if (dissector_uses_key(flow_dissector,
+			       FLOW_DISSECTOR_KEY_CONTROL)) {
+		key_control = skb_flow_dissector_target(flow_dissector,
+							FLOW_DISSECTOR_KEY_CONTROL,
+							target_container);
+		key_control->addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
+		key_control->thoff = min_t(u16, thoff,
+					   skb ? skb->len : hlen);
+		key_control->flags = 0;
+	}
+	if (dissector_uses_key(flow_dissector,
+			       FLOW_DISSECTOR_KEY_BASIC)) {
+		key_basic = skb_flow_dissector_target(flow_dissector,
+						      FLOW_DISSECTOR_KEY_BASIC,
+						      target_container);
+		key_basic->n_proto = htons(ETH_P_IPV6);
+		key_basic->ip_proto = iph->nexthdr;
+	}
+	if (dissector_uses_key(flow_dissector,
+			       FLOW_DISSECTOR_KEY_IPV6_ADDRS)) {
+		key_addrs = skb_flow_dissector_target(flow_dissector,
+						      FLOW_DISSECTOR_KEY_IPV6_ADDRS,
+						      target_container);
+		memcpy(&key_addrs->v6addrs.src, &iph->saddr,
+		       sizeof(key_addrs->v6addrs.src));
+		memcpy(&key_addrs->v6addrs.dst, &iph->daddr,
+		       sizeof(key_addrs->v6addrs.dst));
+	}
+	if (dissector_uses_key(flow_dissector,
+			       FLOW_DISSECTOR_KEY_PORTS)) {
+		const __be32 *ports = (const __be32 *)
+			((const u8 *)data + thoff);
+
+		key_ports = skb_flow_dissector_target(flow_dissector,
+						      FLOW_DISSECTOR_KEY_PORTS,
+						      target_container);
+		key_ports->ports = *ports;
+	}
+
+	return true;
+}
+
+/* Strip up to two 802.1Q/802.1AD tags: outer tag ->
+ * FLOW_DISSECTOR_KEY_VLAN, inner -> _CVLAN, mirroring the slow path's
+ * MAX -> VLAN -> CVLAN state machine; more than two tags defer.
+ * Depth 0 is gated by the vlan key, depth >= 1 by the qinq key (the
+ * qinq sysctl also flips vlan on -- see the proc_handlers).
+ */
+static bool flow_dissect_fast_vlan(const struct sk_buff *skb,
+				   struct flow_dissector *flow_dissector,
+				   void *target_container,
+				   const void *data,
+				   __be16 proto, int nhoff, int hlen,
+				   int vlan_depth)
+{
+	struct flow_dissector_key_num_of_vlans *key_nvs;
+	struct flow_dissector_key_vlan *key_vlan;
+	enum flow_dissector_key_id vlan_key;
+	__be16 inner_proto;
+	__be16 saved_tpid;
+	u16 tci_prio;
+	u16 tci_id;
+	bool ok;
+
+	if (vlan_depth >= 1 &&
+	    !static_branch_unlikely(&flow_dissector_qinq_key))
+		return false;
+	if (vlan_depth >= 2)
+		return false;
+
+	vlan_key = vlan_depth == 0 ?
+		   FLOW_DISSECTOR_KEY_VLAN :
+		   FLOW_DISSECTOR_KEY_CVLAN;
+	saved_tpid = proto;
+
+	/* HW-stripped tag is only ever the outermost. */
+	if (vlan_depth == 0 && skb && skb_vlan_tag_present(skb)) {
+		tci_id = skb_vlan_tag_get_id(skb);
+		tci_prio = skb_vlan_tag_get_prio(skb);
+		inner_proto = skb->protocol;
+	} else {
+		const struct vlan_hdr *vlan;
+
+		if (unlikely(hlen - nhoff < (int)sizeof(*vlan)))
+			return false;
+		vlan = (const struct vlan_hdr *)((const u8 *)data + nhoff);
+		tci_id = ntohs(vlan->h_vlan_TCI) & VLAN_VID_MASK;
+		tci_prio = (ntohs(vlan->h_vlan_TCI) &
+			    VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
+		inner_proto = vlan->h_vlan_encapsulated_proto;
+		nhoff += (int)sizeof(*vlan);
+	}
+
+	if (dissector_uses_key(flow_dissector, vlan_key)) {
+		key_vlan = skb_flow_dissector_target(flow_dissector,
+						     vlan_key,
+						     target_container);
+		key_vlan->vlan_id = tci_id;
+		key_vlan->vlan_priority = tci_prio;
+		key_vlan->vlan_tpid = saved_tpid;
+		key_vlan->vlan_eth_type = inner_proto;
+	}
+	if (dissector_uses_key(flow_dissector,
+			       FLOW_DISSECTOR_KEY_NUM_OF_VLANS)) {
+		key_nvs = skb_flow_dissector_target(flow_dissector,
+						    FLOW_DISSECTOR_KEY_NUM_OF_VLANS,
+						    target_container);
+		key_nvs->num_of_vlans++;
+	}
+
+	switch (inner_proto) {
+	case htons(ETH_P_IP):
+		ok = flow_dissect_fast_ipv4(skb, flow_dissector,
+					    target_container, data,
+					    nhoff, hlen, vlan_depth + 2);
+		break;
+	case htons(ETH_P_IPV6):
+		ok = flow_dissect_fast_ipv6(skb, flow_dissector,
+					    target_container, data,
+					    nhoff, hlen, vlan_depth + 2);
+		break;
+	case htons(ETH_P_8021Q):
+	case htons(ETH_P_8021AD):
+		ok = flow_dissect_fast_vlan(skb, flow_dissector,
+					    target_container, data,
+					    inner_proto, nhoff, hlen,
+					    vlan_depth + 1);
+		break;
+	default:
+		return false;
+	}
+
+	/* Count only on full success -- a miss defers and the slow path
+	 * counts the occurrence. Depth 0 counts vlan, depth >= 1 qinq; a
+	 * double-tagged hit counts both, as the slow path does.
+	 */
+	if (ok)
+		flow_dissector_count_fast(vlan_depth == 0 ?
+					  FLOW_DISSECTOR_SHAPE_VLAN :
+					  FLOW_DISSECTOR_SHAPE_QINQ);
+	return ok;
+}
+
+/* PPPoE session (RFC 2516) + 2-byte PPP protocol: write
+ * FLOW_DISSECTOR_KEY_PPPOE if requested, then tail-call the eth_ip
+ * fast-path for PPP_IP / PPP_IPV6. Anything else (PFC-compressed
+ * protocol, LCP, MPLS) defers.
+ */
+static bool flow_dissect_fast_pppoe(const struct sk_buff *skb,
+				    struct flow_dissector *flow_dissector,
+				    void *target_container,
+				    const void *data,
+				    int nhoff, int hlen)
+{
+	struct flow_dissector_key_pppoe *key_pppoe;
+	const struct {
+		struct pppoe_hdr hdr;
+		__be16 proto;
+	} *hdr;
+	__be16 inner_eth_proto;
+	u16 ppp_proto;
+	bool ok;
+
+	if (unlikely(hlen - nhoff < (int)sizeof(*hdr)))
+		return false;
+	hdr = (const void *)((const u8 *)data + nhoff);
+	if (!is_pppoe_ses_hdr_valid(&hdr->hdr))
+		return false;
+
+	ppp_proto = ntohs(hdr->proto);
+	switch (ppp_proto) {
+	case PPP_IP:
+		inner_eth_proto = htons(ETH_P_IP);
+		break;
+	case PPP_IPV6:
+		inner_eth_proto = htons(ETH_P_IPV6);
+		break;
+	default:
+		/* MPLS unicast/multicast + everything else (LCP, IPCP,
+		 * compressed PFC, ...) defers to the slow path.
+		 */
+		return false;
+	}
+
+	if (dissector_uses_key(flow_dissector,
+			       FLOW_DISSECTOR_KEY_PPPOE)) {
+		key_pppoe = skb_flow_dissector_target(flow_dissector,
+						      FLOW_DISSECTOR_KEY_PPPOE,
+						      target_container);
+		key_pppoe->session_id = hdr->hdr.sid;
+		key_pppoe->ppp_proto = htons(ppp_proto);
+		key_pppoe->type = htons(ETH_P_PPP_SES);
+	}
+
+	nhoff += PPPOE_SES_HLEN;
+
+	if (inner_eth_proto == htons(ETH_P_IP))
+		ok = flow_dissect_fast_ipv4(skb, flow_dissector,
+					    target_container, data,
+					    nhoff, hlen, 2);
+	else
+		ok = flow_dissect_fast_ipv6(skb, flow_dissector,
+					    target_container, data,
+					    nhoff, hlen, 2);
+
+	if (ok)
+		flow_dissector_count_fast(FLOW_DISSECTOR_SHAPE_PPPOE);
+	return ok;
+}
+
+/* Single MPLS label (BoS=1): write FLOW_DISSECTOR_KEY_MPLS lse[0]
+ * when requested and stop -- the slow path returns OUT_GOOD on BoS
+ * without descending into the inner packet, so the fast path must
+ * not tail-call either. Multi-label stacks defer.
+ */
+static bool flow_dissect_fast_mpls(const struct sk_buff *skb,
+				   struct flow_dissector *flow_dissector,
+				   void *target_container,
+				   const void *data,
+				   __be16 proto, int nhoff, int hlen)
+{
+	struct flow_dissector_key_control *key_control;
+	struct flow_dissector_key_basic *key_basic;
+	struct flow_dissector_key_mpls *key_mpls;
+	struct flow_dissector_mpls_lse *lse;
+	const struct mpls_label *hdr;
+	u32 entry, label, bos;
+
+	if (unlikely(hlen - nhoff < (int)sizeof(*hdr)))
+		return false;
+	hdr = (const struct mpls_label *)((const u8 *)data + nhoff);
+	entry = ntohl(hdr->entry);
+	bos = (entry & MPLS_LS_S_MASK) >> MPLS_LS_S_SHIFT;
+
+	/* Multi-label stack: defer. */
+	if (!bos)
+		return false;
+
+	/* Neither MPLS key requested: the slow path returns OUT_GOOD without
+	 * writing the key; skipping the write block matches it.
+	 */
+	label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
+
+	if (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_MPLS)) {
+		key_mpls = skb_flow_dissector_target(flow_dissector,
+						     FLOW_DISSECTOR_KEY_MPLS,
+						     target_container);
+		lse = &key_mpls->ls[0];
+		lse->mpls_ttl = (entry & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT;
+		lse->mpls_bos = bos;
+		lse->mpls_tc = (entry & MPLS_LS_TC_MASK) >> MPLS_LS_TC_SHIFT;
+		lse->mpls_label = label;
+		dissector_set_mpls_lse(key_mpls, 0);
+	}
+
+	/* Mirror the slow path's out_good terminal: nhoff advances past the
+	 * LSE, then thoff/basic are written from the final proto/ip_proto.
+	 */
+	nhoff += (int)sizeof(*hdr);
+	if (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_CONTROL)) {
+		key_control = skb_flow_dissector_target(flow_dissector,
+							FLOW_DISSECTOR_KEY_CONTROL,
+							target_container);
+		key_control->thoff = min_t(u16, nhoff,
+					   skb ? skb->len : hlen);
+	}
+	if (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_BASIC)) {
+		key_basic = skb_flow_dissector_target(flow_dissector,
+						      FLOW_DISSECTOR_KEY_BASIC,
+						      target_container);
+		key_basic->n_proto = proto;
+		key_basic->ip_proto = 0;
+	}
+
+	flow_dissector_count_fast(FLOW_DISSECTOR_SHAPE_MPLS);
+	return true;
+}
+
+/* IPIP / 4in6 / 6in4 inner descent: recurse into the inner IP
+ * fast-path, then stamp FLOW_DIS_ENCAPSULATION -- the inner helper
+ * zeros key_control->flags, so the ENCAP write must come after.
+ */
+static bool flow_dissect_fast_ipip_inner(const struct sk_buff *skb,
+					 struct flow_dissector *flow_dissector,
+					 void *target_container,
+					 const void *data,
+					 __be16 inner_eth_proto,
+					 int inner_nhoff, int hlen, int num_hdrs)
+{
+	struct flow_dissector_key_control *key_control;
+	bool ok;
+
+	/* Mirror the slow path's MAX_FLOW_DISSECT_HDRS budget; past the cap
+	 * defer, so both paths stop at the same depth.
+	 */
+	if (++num_hdrs > MAX_FLOW_DISSECT_HDRS)
+		return false;
+
+	if (inner_eth_proto == htons(ETH_P_IP))
+		ok = flow_dissect_fast_ipv4(skb, flow_dissector,
+					    target_container, data,
+					    inner_nhoff, hlen, num_hdrs);
+	else if (inner_eth_proto == htons(ETH_P_IPV6))
+		ok = flow_dissect_fast_ipv6(skb, flow_dissector,
+					    target_container, data,
+					    inner_nhoff, hlen, num_hdrs);
+	else
+		return false;
+
+	if (!ok)
+		return false;
+
+	if (dissector_uses_key(flow_dissector,
+			       FLOW_DISSECTOR_KEY_CONTROL)) {
+		key_control = skb_flow_dissector_target(flow_dissector,
+							FLOW_DISSECTOR_KEY_CONTROL,
+							target_container);
+		key_control->flags |= FLOW_DIS_ENCAPSULATION;
+	}
+	flow_dissector_count_fast(FLOW_DISSECTOR_SHAPE_IPIP);
+	return true;
+}
+
+/* Plain-GRE inner descent (version 0, no flags, inner IP): a 4-byte
+ * base header the slow path steps over with PROTO_AGAIN. Any flags,
+ * version 1 (PPTP) or a non-IP inner defers. ENCAP is stamped after
+ * the inner pass, which zeros key_control->flags.
+ */
+static bool flow_dissect_fast_gre_inner(const struct sk_buff *skb,
+					struct flow_dissector *flow_dissector,
+					void *target_container,
+					const void *data,
+					int nhoff, int hlen, int num_hdrs)
+{
+	struct flow_dissector_key_control *key_control;
+	const struct gre_base_hdr *hdr;
+	__be16 inner_proto;
+	int inner_nhoff;
+	bool ok;
+
+	/* Same MAX_FLOW_DISSECT_HDRS budget as flow_dissect_fast_ipip_inner(). */
+	if (++num_hdrs > MAX_FLOW_DISSECT_HDRS)
+		return false;
+
+	if (unlikely(hlen - nhoff < (int)sizeof(*hdr)))
+		return false;
+	hdr = (const struct gre_base_hdr *)((const u8 *)data + nhoff);
+
+	/* flags field carries the GRE control flags *and* the 3-bit
+	 * version in its low bits. A zero word means "no flags set
+	 * AND version 0" — the byte-identical fast subset.
+	 */
+	if (hdr->flags != 0)
+		return false;
+
+	switch (hdr->protocol) {
+	case htons(ETH_P_IP):
+		inner_proto = htons(ETH_P_IP);
+		break;
+	case htons(ETH_P_IPV6):
+		inner_proto = htons(ETH_P_IPV6);
+		break;
+	default:
+		return false;
+	}
+
+	inner_nhoff = nhoff + (int)sizeof(*hdr);
+
+	if (inner_proto == htons(ETH_P_IP))
+		ok = flow_dissect_fast_ipv4(skb, flow_dissector,
+					    target_container, data,
+					    inner_nhoff, hlen, num_hdrs);
+	else
+		ok = flow_dissect_fast_ipv6(skb, flow_dissector,
+					    target_container, data,
+					    inner_nhoff, hlen, num_hdrs);
+
+	if (!ok)
+		return false;
+
+	/* Re-establish ENCAP after the inner pass zeroed key_control->flags. */
+	if (dissector_uses_key(flow_dissector,
+			       FLOW_DISSECTOR_KEY_CONTROL)) {
+		key_control = skb_flow_dissector_target(flow_dissector,
+							FLOW_DISSECTOR_KEY_CONTROL,
+							target_container);
+		key_control->flags |= FLOW_DIS_ENCAPSULATION;
+	}
+	flow_dissector_count_fast(FLOW_DISSECTOR_SHAPE_GRE);
+	return true;
+}
+
+/* Did a fast-path leaf stamp FLOW_DIS_ENCAPSULATION? The dispatcher
+ * counts eth_ip only for plain top-level IP; descents count under
+ * their own shape (UDP-tunnel descents not at all).
+ */
+static bool flow_dissect_fast_is_encap(struct flow_dissector *flow_dissector,
+				       void *target_container)
+{
+	struct flow_dissector_key_control *key_control;
+
+	if (!dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_CONTROL))
+		return false;
+	key_control = skb_flow_dissector_target(flow_dissector,
+						FLOW_DISSECTOR_KEY_CONTROL,
+						target_container);
+	return key_control->flags & FLOW_DIS_ENCAPSULATION;
+}
+
+/* Top-level dispatcher: eligibility check (only the two standard
+ * dissectors and flag subset) + per-proto switch with per-shape
+ * static_branch gating. Each case's branch is a forward not-taken JMP
+ * when its sysctl is 0 — matches the slow-path cost.
+ */
+static bool flow_dissect_fast(const struct sk_buff *skb,
+			      struct flow_dissector *flow_dissector,
+			      void *target_container,
+			      const void *data,
+			      __be16 proto, int nhoff, int hlen,
+			      unsigned int flags)
+{
+	if (flow_dissector != &flow_keys_dissector &&
+	    flow_dissector != &flow_keys_dissector_symmetric)
+		return false;
+
+	/* skb_get_hash() -- behind RPS/RFS, fq, fq_codel, cake -- passes
+	 * FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL on every dissect, so the
+	 * flag must be admitted or the fast path never runs for the
+	 * kernel's main consumers. Its only semantic (stop early on a
+	 * non-zero IPv6 flow label) is subsumed by the IPv6 fast path
+	 * deferring on any non-zero label. Any other flag defers.
+	 */
+	if (flags & ~(unsigned int)(FLOW_DISSECTOR_F_PARSE_1ST_FRAG |
+				    FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL))
+		return false;
+
+	switch (proto) {
+	case htons(ETH_P_8021Q):
+	case htons(ETH_P_8021AD):
+		if (!static_branch_unlikely(&flow_dissector_vlan_key))
+			return false;
+		return flow_dissect_fast_vlan(skb, flow_dissector,
+					      target_container, data,
+					      proto, nhoff, hlen, 0);
+	case htons(ETH_P_IP):
+		if (!static_branch_unlikely(&flow_dissector_eth_ip_key))
+			return false;
+		if (!flow_dissect_fast_ipv4(skb, flow_dissector,
+					    target_container, data,
+					    nhoff, hlen, 1))
+			return false;
+		/* Plain top-level eth+IP only; descents count under their own shape. */
+		if (!flow_dissect_fast_is_encap(flow_dissector, target_container))
+			flow_dissector_count_fast(FLOW_DISSECTOR_SHAPE_ETH_IP);
+		return true;
+	case htons(ETH_P_IPV6):
+		if (!static_branch_unlikely(&flow_dissector_eth_ip_key))
+			return false;
+		if (!flow_dissect_fast_ipv6(skb, flow_dissector,
+					    target_container, data,
+					    nhoff, hlen, 1))
+			return false;
+		if (!flow_dissect_fast_is_encap(flow_dissector, target_container))
+			flow_dissector_count_fast(FLOW_DISSECTOR_SHAPE_ETH_IP);
+		return true;
+	case htons(ETH_P_PPP_SES):
+		if (!static_branch_unlikely(&flow_dissector_pppoe_key))
+			return false;
+		return flow_dissect_fast_pppoe(skb, flow_dissector,
+					       target_container, data,
+					       nhoff, hlen);
+	case htons(ETH_P_MPLS_UC):
+	case htons(ETH_P_MPLS_MC):
+		if (!static_branch_unlikely(&flow_dissector_mpls_key))
+			return false;
+		return flow_dissect_fast_mpls(skb, flow_dissector,
+					      target_container, data,
+					      proto, nhoff, hlen);
+	default:
+		return false;
+	}
+}
+
 /**
  * __skb_flow_dissect - extract the flow_keys struct and return it
  * @net: associated network namespace, derived from @skb if NULL
@@ -1070,6 +1846,8 @@ bool __skb_flow_dissect(const struct net *net,
 	bool mpls_el = false;
 	int mpls_lse = 0;
 	int num_hdrs = 0;
+	int nhoff_init = 0;
+	bool eth_ip_top = false;
 	u8 ip_proto = 0;
 	bool ret;
 
@@ -1117,59 +1895,72 @@ bool __skb_flow_dissect(const struct net *net,
 					      FLOW_DISSECTOR_KEY_BASIC,
 					      target_container);
 
-	rcu_read_lock();
+	if (static_branch_unlikely(&netns_bpf_flow_dissector_enabled)) {
+		rcu_read_lock();
 
-	if (skb) {
-		if (!net) {
-			if (skb->dev)
-				net = dev_net_rcu(skb->dev);
-			else if (skb->sk)
-				net = sock_net(skb->sk);
+		if (skb) {
+			if (!net) {
+				if (skb->dev)
+					net = dev_net_rcu(skb->dev);
+				else if (skb->sk)
+					net = sock_net(skb->sk);
+			}
 		}
-	}
 
-	DEBUG_NET_WARN_ON_ONCE(!net);
-	if (net) {
-		enum netns_bpf_attach_type type = NETNS_BPF_FLOW_DISSECTOR;
-		struct bpf_prog_array *run_array;
-
-		run_array = rcu_dereference(init_net.bpf.run_array[type]);
-		if (!run_array)
-			run_array = rcu_dereference(net->bpf.run_array[type]);
-
-		if (run_array) {
-			struct bpf_flow_keys flow_keys;
-			struct bpf_flow_dissector ctx = {
-				.flow_keys = &flow_keys,
-				.data = data,
-				.data_end = data + hlen,
-			};
-			__be16 n_proto = proto;
-			struct bpf_prog *prog;
-			u32 result;
-
-			if (skb) {
-				ctx.skb = skb;
-				/* we can't use 'proto' in the skb case
-				 * because it might be set to skb->vlan_proto
-				 * which has been pulled from the data
-				 */
-				n_proto = skb->protocol;
-			}
+		DEBUG_NET_WARN_ON_ONCE(!net);
+		if (net) {
+			enum netns_bpf_attach_type type = NETNS_BPF_FLOW_DISSECTOR;
+			struct bpf_prog_array *run_array;
+
+			run_array = rcu_dereference(init_net.bpf.run_array[type]);
+			if (!run_array)
+				run_array = rcu_dereference(net->bpf.run_array[type]);
+
+			if (run_array) {
+				struct bpf_flow_keys flow_keys;
+				struct bpf_flow_dissector ctx = {
+					.flow_keys = &flow_keys,
+					.data = data,
+					.data_end = data + hlen,
+				};
+				__be16 n_proto = proto;
+				struct bpf_prog *prog;
+				u32 result;
+
+				if (skb) {
+					ctx.skb = skb;
+					/* we can't use 'proto' in the skb case
+					 * because it might be set to
+					 * skb->vlan_proto which has been pulled
+					 * from the data
+					 */
+					n_proto = skb->protocol;
+				}
 
-			prog = READ_ONCE(run_array->items[0].prog);
-			result = bpf_flow_dissect(prog, &ctx, n_proto, nhoff,
-						  hlen, flags);
-			if (result != BPF_FLOW_DISSECTOR_CONTINUE) {
-				__skb_flow_bpf_to_target(&flow_keys, flow_dissector,
-							 target_container);
-				rcu_read_unlock();
-				return result == BPF_OK;
+				prog = READ_ONCE(run_array->items[0].prog);
+				result = bpf_flow_dissect(prog, &ctx, n_proto,
+							  nhoff, hlen, flags);
+				if (result != BPF_FLOW_DISSECTOR_CONTINUE) {
+					__skb_flow_bpf_to_target(&flow_keys,
+								 flow_dissector,
+								 target_container);
+					rcu_read_unlock();
+					return result == BPF_OK;
+				}
 			}
 		}
+
+		rcu_read_unlock();
 	}
 
-	rcu_read_unlock();
+	/* Opt-in fast-path; flow_dissect_fast() does the eligibility check
+	 * and per-shape gating.
+	 */
+	this_cpu_inc(flow_dissector_pcpu_stats.dissects);
+
+	if (flow_dissect_fast(skb, flow_dissector, target_container,
+			      data, proto, nhoff, hlen, flags))
+		return true;
 
 	if (dissector_uses_key(flow_dissector,
 			       FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
@@ -1200,6 +1991,8 @@ bool __skb_flow_dissect(const struct net *net,
 		key_num_of_vlans->num_of_vlans = 0;
 	}
 
+	nhoff_init = nhoff;
+
 proto_again:
 	fdret = FLOW_DISSECT_RET_CONTINUE;
 
@@ -1214,6 +2007,10 @@ bool __skb_flow_dissect(const struct net *net,
 			break;
 		}
 
+		/* Top-level eth+IPv4: eth_ip shape candidate (confirmed at out:). */
+		if (nhoff == nhoff_init)
+			eth_ip_top = true;
+
 		nhoff += iph->ihl * 4;
 
 		ip_proto = iph->protocol;
@@ -1262,6 +2059,9 @@ bool __skb_flow_dissect(const struct net *net,
 			break;
 		}
 
+		if (nhoff == nhoff_init)
+			eth_ip_top = true;
+
 		ip_proto = iph->nexthdr;
 		nhoff += sizeof(struct ipv6hdr);
 
@@ -1335,8 +2135,12 @@ bool __skb_flow_dissect(const struct net *net,
 
 		if (dissector_vlan == FLOW_DISSECTOR_KEY_MAX) {
 			dissector_vlan = FLOW_DISSECTOR_KEY_VLAN;
+			/* First (outer) tag: the vlan fast-path shape. */
+			flow_dissector_count_slow(FLOW_DISSECTOR_SHAPE_VLAN);
 		} else if (dissector_vlan == FLOW_DISSECTOR_KEY_VLAN) {
 			dissector_vlan = FLOW_DISSECTOR_KEY_CVLAN;
+			/* Second tag: the qinq (double-tag) fast-path shape. */
+			flow_dissector_count_slow(FLOW_DISSECTOR_SHAPE_QINQ);
 		} else {
 			fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
 			break;
@@ -1382,6 +2186,8 @@ bool __skb_flow_dissect(const struct net *net,
 			break;
 		}
 
+		flow_dissector_count_slow(FLOW_DISSECTOR_SHAPE_PPPOE);
+
 		/* PFC (compressed 1-byte protocol) frames are not processed.
 		 * A compressed protocol field has the least significant bit of
 		 * the most significant octet set, which will fail the following
@@ -1446,6 +2252,7 @@ bool __skb_flow_dissect(const struct net *net,
 
 	case htons(ETH_P_MPLS_UC):
 	case htons(ETH_P_MPLS_MC):
+		flow_dissector_count_slow(FLOW_DISSECTOR_SHAPE_MPLS);
 		fdret = __skb_flow_dissect_mpls(skb, flow_dissector,
 						target_container, data,
 						nhoff, hlen, mpls_lse,
@@ -1543,6 +2350,7 @@ bool __skb_flow_dissect(const struct net *net,
 			fdret = FLOW_DISSECT_RET_OUT_GOOD;
 			break;
 		}
+		flow_dissector_count_slow(FLOW_DISSECTOR_SHAPE_GRE);
 
 		fdret = __skb_flow_dissect_gre(skb, key_control, flow_dissector,
 					       target_container, data,
@@ -1605,6 +2413,10 @@ bool __skb_flow_dissect(const struct net *net,
 			fdret = FLOW_DISSECT_RET_OUT_GOOD;
 			break;
 		}
+		/* Counted below the STOP check: a stop-flagged dissect is
+		 * one the fast path could never have handled.
+		 */
+		flow_dissector_count_slow(FLOW_DISSECTOR_SHAPE_IPIP);
 
 		proto = htons(ETH_P_IP);
 
@@ -1696,6 +2508,15 @@ bool __skb_flow_dissect(const struct net *net,
 	key_basic->n_proto = proto;
 	key_basic->ip_proto = ip_proto;
 
+	/* eth_ip shape: top-level eth+IP, TCP/UDP, no encap -- counted here
+	 * because the fast path returns earlier; with the gate off this is
+	 * the shape's eligible-fraction signal.
+	 */
+	if (ret && eth_ip_top &&
+	    !(key_control->flags & FLOW_DIS_ENCAPSULATION) &&
+	    (ip_proto == IPPROTO_TCP || ip_proto == IPPROTO_UDP))
+		flow_dissector_count_slow(FLOW_DISSECTOR_SHAPE_ETH_IP);
+
 	return ret;
 
 out_bad:
@@ -1867,8 +2688,6 @@ void make_flow_keys_digest(struct flow_keys_digest *digest,
 }
 EXPORT_SYMBOL(make_flow_keys_digest);
 
-static struct flow_dissector flow_keys_dissector_symmetric __read_mostly;
-
 u32 __skb_get_hash_symmetric_net(const struct net *net, const struct sk_buff *skb)
 {
 	struct flow_keys keys;
@@ -2090,6 +2909,36 @@ EXPORT_SYMBOL(flow_keys_dissector);
 struct flow_dissector flow_keys_basic_dissector __read_mostly;
 EXPORT_SYMBOL(flow_keys_basic_dissector);
 
+#if IS_ENABLED(CONFIG_FLOW_DISSECTOR_KUNIT_TEST)
+/* Test-only accessor: the symmetric dissector is file-static but is
+ * the second dissector the fast-path eligibility gate admits.
+ */
+struct flow_dissector *flow_keys_dissector_symmetric_kunit(void)
+{
+	return &flow_keys_dissector_symmetric;
+}
+EXPORT_SYMBOL_GPL(flow_keys_dissector_symmetric_kunit);
+
+/* Test-only accessor: summed fast-path hits, the observable for the
+ * suite's gates-off negative.
+ */
+u64 flow_dissector_fast_hits_kunit(void)
+{
+	u64 sum = 0;
+	int cpu, i;
+
+	for_each_possible_cpu(cpu) {
+		const struct flow_dissector_stats *s =
+			per_cpu_ptr(&flow_dissector_pcpu_stats, cpu);
+
+		for (i = 0; i < FLOW_DISSECTOR_SHAPE__MAX; i++)
+			sum += READ_ONCE(s->fast_hits[i]);
+	}
+	return sum;
+}
+EXPORT_SYMBOL_GPL(flow_dissector_fast_hits_kunit);
+#endif
+
 static int __init init_default_flow_dissectors(void)
 {
 	skb_flow_dissector_init(&flow_keys_dissector,
@@ -2104,3 +2953,176 @@ static int __init init_default_flow_dissectors(void)
 	return 0;
 }
 core_initcall(init_default_flow_dissectors);
+
+/* Per-shape fast-path sysctls under /proc/sys/net/flow_dissector/. */
+/* proc_handler for net.flow_dissector.vlan. Writes of 0 also clear
+ * flow_dissector_qinq_key — QinQ depth-2 is meaningless when the
+ * outer single-VLAN gate is off, so the slow path would have to
+ * handle every VLAN-tagged packet anyway.
+ */
+static int proc_set_vlan_key(const struct ctl_table *table, int write,
+			     void *buffer, size_t *lenp, loff_t *ppos)
+{
+	int ret;
+
+	ret = proc_do_static_key(table, write, buffer, lenp, ppos);
+	if (ret == 0 && write &&
+	    !static_branch_unlikely(&flow_dissector_vlan_key) &&
+	    static_branch_unlikely(&flow_dissector_qinq_key))
+		static_branch_disable(&flow_dissector_qinq_key);
+	return ret;
+}
+
+/* proc_handler for net.flow_dissector.qinq. Writes of 1 also enable
+ * flow_dissector_vlan_key — QinQ extends the VLAN fast-path to depth
+ * 2; it cannot fire when the depth-0 entry is gated off.
+ */
+static int proc_set_qinq_key(const struct ctl_table *table, int write,
+			     void *buffer, size_t *lenp, loff_t *ppos)
+{
+	int ret;
+
+	ret = proc_do_static_key(table, write, buffer, lenp, ppos);
+	if (ret == 0 && write &&
+	    static_branch_unlikely(&flow_dissector_qinq_key) &&
+	    !static_branch_unlikely(&flow_dissector_vlan_key))
+		static_branch_enable(&flow_dissector_vlan_key);
+	return ret;
+}
+
+static struct ctl_table flow_dissector_sysctl_table[] = {
+	{
+		.procname	= "eth_ip",
+		.data		= &flow_dissector_eth_ip_key.key,
+		.maxlen		= sizeof(flow_dissector_eth_ip_key),
+		.mode		= 0644,
+		.proc_handler	= proc_do_static_key,
+	},
+	{
+		.procname	= "vlan",
+		.data		= &flow_dissector_vlan_key.key,
+		.maxlen		= sizeof(flow_dissector_vlan_key),
+		.mode		= 0644,
+		.proc_handler	= proc_set_vlan_key,
+	},
+	{
+		.procname	= "qinq",
+		.data		= &flow_dissector_qinq_key.key,
+		.maxlen		= sizeof(flow_dissector_qinq_key),
+		.mode		= 0644,
+		.proc_handler	= proc_set_qinq_key,
+	},
+	{
+		.procname	= "pppoe",
+		.data		= &flow_dissector_pppoe_key.key,
+		.maxlen		= sizeof(flow_dissector_pppoe_key),
+		.mode		= 0644,
+		.proc_handler	= proc_do_static_key,
+	},
+	{
+		.procname	= "mpls",
+		.data		= &flow_dissector_mpls_key.key,
+		.maxlen		= sizeof(flow_dissector_mpls_key),
+		.mode		= 0644,
+		.proc_handler	= proc_do_static_key,
+	},
+	{
+		.procname	= "ipip",
+		.data		= &flow_dissector_ipip_key.key,
+		.maxlen		= sizeof(flow_dissector_ipip_key),
+		.mode		= 0644,
+		.proc_handler	= proc_do_static_key,
+	},
+	{
+		.procname	= "gre",
+		.data		= &flow_dissector_gre_key.key,
+		.maxlen		= sizeof(flow_dissector_gre_key),
+		.mode		= 0644,
+		.proc_handler	= proc_do_static_key,
+	},
+};
+
+static const char * const flow_dissector_shape_names[FLOW_DISSECTOR_SHAPE__MAX] = {
+	[FLOW_DISSECTOR_SHAPE_ETH_IP] = "eth_ip",
+	[FLOW_DISSECTOR_SHAPE_VLAN]   = "vlan",
+	[FLOW_DISSECTOR_SHAPE_QINQ]   = "qinq",
+	[FLOW_DISSECTOR_SHAPE_PPPOE]  = "pppoe",
+	[FLOW_DISSECTOR_SHAPE_MPLS]   = "mpls",
+	[FLOW_DISSECTOR_SHAPE_IPIP]   = "ipip",
+	[FLOW_DISSECTOR_SHAPE_GRE]    = "gre",
+};
+
+static bool flow_dissector_shape_gate(enum flow_dissector_shape shape)
+{
+	switch (shape) {
+	case FLOW_DISSECTOR_SHAPE_ETH_IP:
+		return static_key_enabled(&flow_dissector_eth_ip_key);
+	case FLOW_DISSECTOR_SHAPE_VLAN:
+		return static_key_enabled(&flow_dissector_vlan_key);
+	case FLOW_DISSECTOR_SHAPE_QINQ:
+		return static_key_enabled(&flow_dissector_qinq_key);
+	case FLOW_DISSECTOR_SHAPE_PPPOE:
+		return static_key_enabled(&flow_dissector_pppoe_key);
+	case FLOW_DISSECTOR_SHAPE_MPLS:
+		return static_key_enabled(&flow_dissector_mpls_key);
+	case FLOW_DISSECTOR_SHAPE_IPIP:
+		return static_key_enabled(&flow_dissector_ipip_key);
+	case FLOW_DISSECTOR_SHAPE_GRE:
+		return static_key_enabled(&flow_dissector_gre_key);
+	default:
+		return false;
+	}
+}
+
+/* /proc/net/flow_dissector_stats: per-shape occurrences (slow path),
+ * fast_hits, and eligible% = (occurrences + fast_hits) / dissects --
+ * the signal a policy layer thresholds against a per-shape
+ * break-even.
+ */
+static int flow_dissector_stats_show(struct seq_file *seq, void *v)
+{
+	u64 occ[FLOW_DISSECTOR_SHAPE__MAX] = {};
+	u64 fast[FLOW_DISSECTOR_SHAPE__MAX] = {};
+	u64 dissects = 0;
+	int cpu, i;
+
+	for_each_possible_cpu(cpu) {
+		const struct flow_dissector_stats *s =
+			per_cpu_ptr(&flow_dissector_pcpu_stats, cpu);
+
+		for (i = 0; i < FLOW_DISSECTOR_SHAPE__MAX; i++) {
+			occ[i]  += READ_ONCE(s->occurrences[i]);
+			fast[i] += READ_ONCE(s->fast_hits[i]);
+		}
+		dissects += READ_ONCE(s->dissects);
+	}
+
+	seq_printf(seq, "%-8s %16s %16s %10s %5s\n",
+		   "shape", "occurrences", "fast_hits", "eligible%", "gate");
+	for (i = 0; i < FLOW_DISSECTOR_SHAPE__MAX; i++) {
+		u64 total = occ[i] + fast[i];
+		u64 pct_x100 = dissects ? div64_u64(total * 10000, dissects) : 0;
+
+		seq_printf(seq, "%-8s %16llu %16llu %7llu.%02llu %5s\n",
+			   flow_dissector_shape_names[i], occ[i], fast[i],
+			   pct_x100 / 100, pct_x100 % 100,
+			   str_on_off(flow_dissector_shape_gate(i)));
+	}
+	seq_printf(seq, "dissects: %llu\n", dissects);
+	return 0;
+}
+
+static int __init flow_dissector_sysctl_init(void)
+{
+	if (!register_net_sysctl(&init_net, "net/flow_dissector",
+				 flow_dissector_sysctl_table))
+		return -ENOMEM;
+
+	/* Global (init_net) counters — matches the global gates; per-netns
+	 * is a noted follow-up. A missing proc file is not fatal.
+	 */
+	proc_create_single("flow_dissector_stats", 0444, init_net.proc_net,
+			   flow_dissector_stats_show);
+	return 0;
+}
+late_initcall(flow_dissector_sysctl_init);
diff --git a/net/core/flow_dissector_test.c b/net/core/flow_dissector_test.c
new file mode 100644
index 00000000000000..e0014affda7f93
--- /dev/null
+++ b/net/core/flow_dissector_test.c
@@ -0,0 +1,1053 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * KUnit equivalence tests for the flow dissector opt-in fast paths.
+ *
+ * Every fast-path shape contracts to be byte-identical with the slow
+ * path. Each corpus packet is dissected twice into zeroed containers
+ * -- gates off, then gates on -- and the return values, the full
+ * struct flow_keys and flow_hash_from_keys() must match exactly, for
+ * both eligible dissectors (flow_keys_dissector and the file-static
+ * symmetric one). (A fast-path miss cannot leak partial writes to
+ * callers: flow_dissect_fast() is only invoked from
+ * __skb_flow_dissect(), which continues into the full slow-path walk
+ * on the same container whenever the fast path returns false.)
+ */
+
+#include <kunit/test.h>
+
+#include <linux/etherdevice.h>
+#include <linux/if_ether.h>
+#include <linux/if_pppox.h>
+#include <linux/if_tunnel.h>
+#include <linux/if_vlan.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <linux/mpls.h>
+#include <linux/netdevice.h>
+#include <linux/ppp_defs.h>
+#include <linux/prandom.h>
+#include <linux/skbuff.h>
+#include <linux/udp.h>
+#include <net/flow_dissector.h>
+#include <net/gre.h>
+#include <net/ip.h>
+#include <net/net_namespace.h>
+
+#define FD_TEST_BUF_LEN 512
+#define FD_FUZZ_ITERS 4000
+
+/* The byte-identical fast-path gates. */
+static struct static_key_false * const fd_fast_gates[] = {
+	&flow_dissector_eth_ip_key,
+	&flow_dissector_vlan_key,
+	&flow_dissector_qinq_key,
+	&flow_dissector_pppoe_key,
+	&flow_dissector_mpls_key,
+	&flow_dissector_ipip_key,
+	&flow_dissector_gre_key,
+};
+
+static void fd_fast_gates_set(bool on)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(fd_fast_gates); i++) {
+		if (on)
+			static_branch_enable(fd_fast_gates[i]);
+		else
+			static_branch_disable(fd_fast_gates[i]);
+	}
+}
+
+/* --- packet builders (network-layer payloads; __skb_flow_dissect is
+ * called in raw-data mode with the L3 proto passed explicitly, so no
+ * Ethernet header is included) ---
+ */
+
+static int put_ports(u8 *buf)
+{
+	__be16 *p = (__be16 *)buf;
+
+	p[0] = htons(0x1234);
+	p[1] = htons(0x5678);
+	return 4;
+}
+
+static int put_ipv4(u8 *buf, u8 ip_proto, u8 ihl, __be16 frag_off)
+{
+	struct iphdr *ip = (struct iphdr *)buf;
+	int hdrlen = ihl * 4;
+
+	memset(ip, 0, hdrlen);
+	ip->version = 4;
+	ip->ihl = ihl;
+	ip->ttl = 64;
+	ip->tot_len = htons(hdrlen + 4);
+	ip->frag_off = frag_off;
+	ip->protocol = ip_proto;
+	ip->saddr = htonl(0xc0a80101);	/* 192.168.1.1 */
+	ip->daddr = htonl(0xc0a80202);	/* 192.168.2.2 */
+	return hdrlen;
+}
+
+static int put_ipv6(u8 *buf, u8 nexthdr, u32 flow_label)
+{
+	struct ipv6hdr *ip6 = (struct ipv6hdr *)buf;
+
+	memset(ip6, 0, sizeof(*ip6));
+	ip6->version = 6;
+	ip6->flow_lbl[0] = (flow_label >> 16) & 0x0f;
+	ip6->flow_lbl[1] = (flow_label >> 8) & 0xff;
+	ip6->flow_lbl[2] = flow_label & 0xff;
+	ip6->payload_len = htons(4);
+	ip6->nexthdr = nexthdr;
+	ip6->hop_limit = 64;
+	ip6->saddr.s6_addr32[0] = htonl(0x20010db8);
+	ip6->saddr.s6_addr32[3] = htonl(1);
+	ip6->daddr.s6_addr32[0] = htonl(0x20010db8);
+	ip6->daddr.s6_addr32[3] = htonl(2);
+	return sizeof(*ip6);
+}
+
+static int put_vlan(u8 *buf, u16 tci, __be16 inner_proto)
+{
+	struct vlan_hdr *vlan = (struct vlan_hdr *)buf;
+
+	vlan->h_vlan_TCI = htons(tci);
+	vlan->h_vlan_encapsulated_proto = inner_proto;
+	return sizeof(*vlan);
+}
+
+static int put_pppoe(u8 *buf, u16 ppp_proto, u16 payload_len)
+{
+	struct pppoe_hdr *hdr = (struct pppoe_hdr *)buf;
+	__be16 *proto = (__be16 *)(buf + sizeof(*hdr));
+
+	memset(hdr, 0, sizeof(*hdr));
+	hdr->ver = 1;
+	hdr->type = 1;
+	hdr->code = 0;
+	hdr->sid = htons(0x42);
+	hdr->length = htons(payload_len + 2);
+	*proto = htons(ppp_proto);
+	return sizeof(*hdr) + 2;
+}
+
+static int put_mpls(u8 *buf, u32 label, u32 bos)
+{
+	struct mpls_label *lse = (struct mpls_label *)buf;
+
+	lse->entry = htonl((label << MPLS_LS_LABEL_SHIFT) |
+			   (bos << MPLS_LS_S_SHIFT) |
+			   (64 << MPLS_LS_TTL_SHIFT));
+	return sizeof(*lse);
+}
+
+static int put_gre(u8 *buf, __be16 flags, __be16 protocol)
+{
+	struct gre_base_hdr *gre = (struct gre_base_hdr *)buf;
+
+	gre->flags = flags;
+	gre->protocol = protocol;
+	return sizeof(*gre);
+}
+
+/* --- composite builders, one per corpus entry --- */
+
+static int build_ipv4_tcp(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_TCP, 5, 0);
+
+	return n + put_ports(buf + n);
+}
+
+static int build_ipv4_udp(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_UDP, 5, 0);
+
+	return n + put_ports(buf + n);
+}
+
+static int build_ipv6_tcp(u8 *buf)
+{
+	int n = put_ipv6(buf, IPPROTO_TCP, 0);
+
+	return n + put_ports(buf + n);
+}
+
+static int build_ipv6_udp(u8 *buf)
+{
+	int n = put_ipv6(buf, IPPROTO_UDP, 0);
+
+	return n + put_ports(buf + n);
+}
+
+static int build_vlan_ipv4_tcp(u8 *buf)
+{
+	int n = put_vlan(buf, 100, htons(ETH_P_IP));
+
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_vlan_ipv6_udp(u8 *buf)
+{
+	int n = put_vlan(buf, 100, htons(ETH_P_IPV6));
+
+	n += put_ipv6(buf + n, IPPROTO_UDP, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_qinq_ipv4_tcp(u8 *buf)
+{
+	int n = put_vlan(buf, 100, htons(ETH_P_8021Q));
+
+	n += put_vlan(buf + n, 200, htons(ETH_P_IP));
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_vlan3_ipv4_tcp(u8 *buf)
+{
+	int n = put_vlan(buf, 100, htons(ETH_P_8021Q));
+
+	n += put_vlan(buf + n, 200, htons(ETH_P_8021Q));
+	n += put_vlan(buf + n, 300, htons(ETH_P_IP));
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_pppoe_ipv4_tcp(u8 *buf)
+{
+	int n = put_pppoe(buf, PPP_IP, 20 + 4);
+
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_pppoe_ipv6_tcp(u8 *buf)
+{
+	int n = put_pppoe(buf, PPP_IPV6, 40 + 4);
+
+	n += put_ipv6(buf + n, IPPROTO_TCP, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_pppoe_lcp(u8 *buf)
+{
+	int n = put_pppoe(buf, PPP_LCP, 4);
+	u8 lcp[4] = { 0x01, 0x01, 0x00, 0x04 };
+
+	memcpy(buf + n, lcp, sizeof(lcp));
+	return n + sizeof(lcp);
+}
+
+static int build_mpls_ipv4(u8 *buf)
+{
+	int n = put_mpls(buf, 1000, 1);
+
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_mpls_multi(u8 *buf)
+{
+	int n = put_mpls(buf, 1000, 0);	/* S=0: not bottom of stack */
+
+	n += put_mpls(buf + n, 2000, 1);
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_ipip(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_IPIP, 5, 0);
+
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_6in4(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_IPV6, 5, 0);
+
+	n += put_ipv6(buf + n, IPPROTO_TCP, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_4in6(u8 *buf)
+{
+	int n = put_ipv6(buf, IPPROTO_IPIP, 0);
+
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_4in6_flowlabel(u8 *buf)
+{
+	int n = put_ipv6(buf, IPPROTO_IPIP, 0xbeef);
+
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_6in6(u8 *buf)
+{
+	int n = put_ipv6(buf, IPPROTO_IPV6, 0);
+
+	n += put_ipv6(buf + n, IPPROTO_TCP, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_gre_ipv4(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_GRE, 5, 0);
+
+	n += put_gre(buf + n, 0, htons(ETH_P_IP));
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_gre_ipv6(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_GRE, 5, 0);
+
+	n += put_gre(buf + n, 0, htons(ETH_P_IPV6));
+	n += put_ipv6(buf + n, IPPROTO_TCP, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_gre6_ipv6(u8 *buf)
+{
+	int n = put_ipv6(buf, IPPROTO_GRE, 0);
+
+	n += put_gre(buf + n, 0, htons(ETH_P_IPV6));
+	n += put_ipv6(buf + n, IPPROTO_TCP, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_gre6_ipv4(u8 *buf)
+{
+	int n = put_ipv6(buf, IPPROTO_GRE, 0);
+
+	n += put_gre(buf + n, 0, htons(ETH_P_IP));
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+/* --- corner-case builders --- */
+
+/* GRE variants that must defer (any non-zero flags/version word). */
+static int build_gre_seq_ipv4(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_GRE, 5, 0);
+
+	n += put_gre(buf + n, GRE_SEQ, htons(ETH_P_IP));
+	memset(buf + n, 0, 4);		/* sequence number */
+	n += 4;
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_gre_key_ipv4(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_GRE, 5, 0);
+
+	n += put_gre(buf + n, GRE_KEY, htons(ETH_P_IP));
+	memset(buf + n, 0, 4);		/* key */
+	n += 4;
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_gre_version1(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_GRE, 5, 0);
+
+	/* GRE version 1 (PPTP) lives in the low bits of the flags word. */
+	n += put_gre(buf + n, htons(0x0001), htons(ETH_P_IP));
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_gre_teb(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_GRE, 5, 0);
+
+	/* Transparent Ethernet bridging inner: fast path defers. */
+	n += put_gre(buf + n, 0, htons(ETH_P_TEB));
+	return n + put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+}
+
+/* An IPv6 extension header (8 bytes, hdrlen field 0). */
+static int put_ext_hdr(u8 *buf, u8 next_proto)
+{
+	memset(buf, 0, 8);
+	buf[0] = next_proto;
+	buf[1] = 0;			/* hdr ext len: (0 + 1) * 8 = 8 bytes */
+	return 8;
+}
+
+static int build_ipv6_hopopts_dest_tcp(u8 *buf)
+{
+	int n = put_ipv6(buf, IPPROTO_HOPOPTS, 0);
+
+	n += put_ext_hdr(buf + n, IPPROTO_DSTOPTS);
+	n += put_ext_hdr(buf + n, IPPROTO_TCP);
+	return n + put_ports(buf + n);
+}
+
+static int build_ipv6_frag_tcp(u8 *buf)
+{
+	int n = put_ipv6(buf, IPPROTO_FRAGMENT, 0);
+
+	memset(buf + n, 0, 8);
+	buf[n] = IPPROTO_TCP;		/* fragment header, offset 0 */
+	*(__be32 *)(buf + n + 4) = htonl(0x12345678);
+	n += 8;
+	return n + put_ports(buf + n);
+}
+
+/* TPID ordering not covered elsewhere: 8021Q outer, 8021AD inner. */
+static int build_vlan_q_then_ad_ipv4(u8 *buf)
+{
+	int n = put_vlan(buf, 100, htons(ETH_P_8021AD));
+
+	n += put_vlan(buf + n, 200, htons(ETH_P_IP));
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+/* IPv4 with a larger options block (IHL 8 => 12 bytes of options). */
+static int build_ipv4_options12_tcp(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_TCP, 8, 0);
+
+	return n + put_ports(buf + n);
+}
+
+/* PPPoE with a PFC-compressed (odd MSB) PPP protocol field: defers. */
+static int build_pppoe_pfc(u8 *buf)
+{
+	int n = put_pppoe(buf, 0x2100, 20 + 4);
+
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+/* Mid-stream fragment: non-zero offset AND MF still set. */
+static int build_ipv4_frag_mid_tcp(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_TCP, 5, htons(IP_MF | 5));
+
+	return n + put_ports(buf + n);
+}
+
+/* GRE optional-field combinations (order: csum+reserved, key, seq). */
+static int build_gre_csum_key_ipv4(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_GRE, 5, 0);
+
+	n += put_gre(buf + n, GRE_CSUM | GRE_KEY, htons(ETH_P_IP));
+	memset(buf + n, 0, 8);		/* checksum + reserved, key */
+	n += 8;
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_gre_csum_key_seq_ipv4(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_GRE, 5, 0);
+
+	n += put_gre(buf + n, GRE_CSUM | GRE_KEY | GRE_SEQ, htons(ETH_P_IP));
+	memset(buf + n, 0, 12);		/* checksum + reserved, key, seq */
+	n += 12;
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+/* Priority-tagged frame (802.1Q VID 0, only PCP bits in the TCI). */
+static int build_vlan_prio_ipv4_tcp(u8 *buf)
+{
+	int n = put_vlan(buf, 5 << VLAN_PRIO_SHIFT, htons(ETH_P_IP));
+
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+/* IPv6 routing extension header before TCP. */
+static int build_ipv6_routing_tcp(u8 *buf)
+{
+	int n = put_ipv6(buf, IPPROTO_ROUTING, 0);
+
+	n += put_ext_hdr(buf + n, IPPROTO_TCP);
+	return n + put_ports(buf + n);
+}
+
+/* Deeply nested IPIP / GRE chains for the recursion cap. */
+static int build_ipip_nest(u8 *buf, int levels)
+{
+	int n = 0, i;
+
+	for (i = 0; i < levels; i++)
+		n += put_ipv4(buf + n, IPPROTO_IPIP, 5, 0);
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_gre_nest(u8 *buf, int levels)
+{
+	int n = 0, i;
+
+	for (i = 0; i < levels; i++) {
+		n += put_ipv4(buf + n, IPPROTO_GRE, 5, 0);
+		n += put_gre(buf + n, 0, htons(ETH_P_IP));
+	}
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_gre_csum_ipv4(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_GRE, 5, 0);
+
+	n += put_gre(buf + n, GRE_CSUM, htons(ETH_P_IP));
+	memset(buf + n, 0, 4);		/* checksum + reserved */
+	n += 4;
+	n += put_ipv4(buf + n, IPPROTO_TCP, 5, 0);
+	return n + put_ports(buf + n);
+}
+
+static int build_ipv4_options_tcp(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_TCP, 6, 0);	/* IHL=6: 4B options */
+
+	return n + put_ports(buf + n);
+}
+
+static int build_ipv4_frag_tcp(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_TCP, 5, htons(IP_MF));
+
+	return n + put_ports(buf + n);
+}
+
+static int build_ipv4_frag_offset_tcp(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_TCP, 5, htons(0x0010));
+
+	return n + put_ports(buf + n);
+}
+
+static int build_ipv4_icmp(u8 *buf)
+{
+	int n = put_ipv4(buf, IPPROTO_ICMP, 5, 0);
+	u8 icmp[8] = { 0x08, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x01 };
+
+	memcpy(buf + n, icmp, sizeof(icmp));
+	return n + sizeof(icmp);
+}
+
+static int build_ipv6_hopopts_tcp(u8 *buf)
+{
+	int n = put_ipv6(buf, IPPROTO_HOPOPTS, 0);
+	u8 hbh[8] = { IPPROTO_TCP, 0, 0, 0, 0, 0, 0, 0 };
+
+	memcpy(buf + n, hbh, sizeof(hbh));
+	n += sizeof(hbh);
+	return n + put_ports(buf + n);
+}
+
+static int build_ipv6_flowlabel_tcp(u8 *buf)
+{
+	int n = put_ipv6(buf, IPPROTO_TCP, 0xbeef);
+
+	return n + put_ports(buf + n);
+}
+
+struct fd_fast_case {
+	const char *name;
+	int (*build)(u8 *buf);
+	__be16 proto;
+	unsigned int flags;
+};
+
+/* htons() is not constant-foldable here without cpu_to_be16 literals;
+ * use cpu_to_be16 for static initializers.
+ */
+static const struct fd_fast_case fd_fast_cases[] = {
+	/* eligible shapes: the fast path should take these */
+	{ "ipv4_tcp", build_ipv4_tcp, cpu_to_be16(ETH_P_IP), 0 },
+	{ "ipv4_udp", build_ipv4_udp, cpu_to_be16(ETH_P_IP), 0 },
+	{ "ipv6_tcp", build_ipv6_tcp, cpu_to_be16(ETH_P_IPV6), 0 },
+	{ "ipv6_udp", build_ipv6_udp, cpu_to_be16(ETH_P_IPV6), 0 },
+	{ "vlan_ipv4_tcp", build_vlan_ipv4_tcp, cpu_to_be16(ETH_P_8021Q), 0 },
+	{ "vlan_ipv6_udp", build_vlan_ipv6_udp, cpu_to_be16(ETH_P_8021Q), 0 },
+	{ "qinq_ipv4_tcp", build_qinq_ipv4_tcp, cpu_to_be16(ETH_P_8021AD), 0 },
+	{ "pppoe_ipv4_tcp", build_pppoe_ipv4_tcp, cpu_to_be16(ETH_P_PPP_SES), 0 },
+	{ "pppoe_ipv6_tcp", build_pppoe_ipv6_tcp, cpu_to_be16(ETH_P_PPP_SES), 0 },
+	{ "mpls_ipv4", build_mpls_ipv4, cpu_to_be16(ETH_P_MPLS_UC), 0 },
+	{ "ipip", build_ipip, cpu_to_be16(ETH_P_IP), 0 },
+	{ "6in4", build_6in4, cpu_to_be16(ETH_P_IP), 0 },
+	{ "4in6", build_4in6, cpu_to_be16(ETH_P_IPV6), 0 },
+	{ "4in6_flowlabel", build_4in6_flowlabel, cpu_to_be16(ETH_P_IPV6), 0 },
+	{ "6in6", build_6in6, cpu_to_be16(ETH_P_IPV6), 0 },
+	{ "gre_ipv4", build_gre_ipv4, cpu_to_be16(ETH_P_IP), 0 },
+	{ "gre6_ipv4", build_gre6_ipv4, cpu_to_be16(ETH_P_IPV6), 0 },
+	{ "gre_ipv6", build_gre_ipv6, cpu_to_be16(ETH_P_IP), 0 },
+	{ "gre6_ipv6", build_gre6_ipv6, cpu_to_be16(ETH_P_IPV6), 0 },
+	/* deliberate fast-path misses: must fall back with identical
+	 * output (and, per the zeroed containers, no partial writes)
+	 */
+	{ "ipv4_options_tcp", build_ipv4_options_tcp, cpu_to_be16(ETH_P_IP), 0 },
+	{ "ipv4_frag_mf", build_ipv4_frag_tcp, cpu_to_be16(ETH_P_IP), 0 },
+	{ "ipv4_frag_mf_1stfrag", build_ipv4_frag_tcp, cpu_to_be16(ETH_P_IP),
+	  FLOW_DISSECTOR_F_PARSE_1ST_FRAG },
+	{ "ipv4_frag_offset", build_ipv4_frag_offset_tcp,
+	  cpu_to_be16(ETH_P_IP), 0 },
+	{ "ipv4_icmp", build_ipv4_icmp, cpu_to_be16(ETH_P_IP), 0 },
+	{ "ipv6_hopopts_tcp", build_ipv6_hopopts_tcp,
+	  cpu_to_be16(ETH_P_IPV6), 0 },
+	{ "ipv6_flowlabel_tcp", build_ipv6_flowlabel_tcp,
+	  cpu_to_be16(ETH_P_IPV6), 0 },
+	{ "vlan3_ipv4_tcp", build_vlan3_ipv4_tcp, cpu_to_be16(ETH_P_8021Q), 0 },
+	{ "pppoe_lcp", build_pppoe_lcp, cpu_to_be16(ETH_P_PPP_SES), 0 },
+	{ "mpls_multi_label", build_mpls_multi, cpu_to_be16(ETH_P_MPLS_UC), 0 },
+	{ "gre_csum_ipv4", build_gre_csum_ipv4, cpu_to_be16(ETH_P_IP), 0 },
+	/* corner cases */
+	{ "gre_seq_ipv4", build_gre_seq_ipv4, cpu_to_be16(ETH_P_IP), 0 },
+	{ "gre_key_ipv4", build_gre_key_ipv4, cpu_to_be16(ETH_P_IP), 0 },
+	{ "gre_version1", build_gre_version1, cpu_to_be16(ETH_P_IP), 0 },
+	{ "gre_teb", build_gre_teb, cpu_to_be16(ETH_P_IP), 0 },
+	{ "ipv6_hopopts_dest_tcp", build_ipv6_hopopts_dest_tcp,
+	  cpu_to_be16(ETH_P_IPV6), 0 },
+	{ "ipv6_frag_tcp", build_ipv6_frag_tcp, cpu_to_be16(ETH_P_IPV6), 0 },
+	{ "vlan_q_then_ad_ipv4", build_vlan_q_then_ad_ipv4,
+	  cpu_to_be16(ETH_P_8021Q), 0 },
+	{ "ipv4_options12_tcp", build_ipv4_options12_tcp,
+	  cpu_to_be16(ETH_P_IP), 0 },
+	{ "pppoe_pfc", build_pppoe_pfc, cpu_to_be16(ETH_P_PPP_SES), 0 },
+	{ "ipv4_frag_mid", build_ipv4_frag_mid_tcp, cpu_to_be16(ETH_P_IP), 0 },
+	{ "ipv4_frag_mid_1stfrag", build_ipv4_frag_mid_tcp,
+	  cpu_to_be16(ETH_P_IP), FLOW_DISSECTOR_F_PARSE_1ST_FRAG },
+	{ "gre_csum_key_ipv4", build_gre_csum_key_ipv4,
+	  cpu_to_be16(ETH_P_IP), 0 },
+	{ "gre_csum_key_seq_ipv4", build_gre_csum_key_seq_ipv4,
+	  cpu_to_be16(ETH_P_IP), 0 },
+	{ "vlan_prio_ipv4_tcp", build_vlan_prio_ipv4_tcp,
+	  cpu_to_be16(ETH_P_8021Q), 0 },
+	{ "ipv6_routing_tcp", build_ipv6_routing_tcp,
+	  cpu_to_be16(ETH_P_IPV6), 0 },
+};
+
+static void fd_fast_case_to_desc(const struct fd_fast_case *c, char *desc)
+{
+	strscpy(desc, c->name, KUNIT_PARAM_DESC_SIZE);
+}
+
+KUNIT_ARRAY_PARAM(fd_fast, fd_fast_cases, fd_fast_case_to_desc);
+
+/* Dissect with gates off then on; returns and output must match. */
+static void fd_check_one(struct kunit *test, struct flow_dissector *fd,
+			 const u8 *data, __be16 proto, int hlen,
+			 unsigned int flags)
+{
+	struct flow_keys keys_slow, keys_fast;
+	bool ret_slow, ret_fast;
+
+	fd_fast_gates_set(false);
+	memset(&keys_slow, 0, sizeof(keys_slow));
+	ret_slow = __skb_flow_dissect(&init_net, NULL, fd, &keys_slow,
+				      data, proto, 0, hlen, flags);
+
+	fd_fast_gates_set(true);
+	memset(&keys_fast, 0, sizeof(keys_fast));
+	ret_fast = __skb_flow_dissect(&init_net, NULL, fd, &keys_fast,
+				      data, proto, 0, hlen, flags);
+	fd_fast_gates_set(false);
+
+	KUNIT_EXPECT_EQ(test, ret_slow, ret_fast);
+	KUNIT_EXPECT_MEMEQ(test, &keys_slow, &keys_fast, sizeof(keys_slow));
+	/* flow_keys -> skb->hash is what consumers see; assert it too. */
+	KUNIT_EXPECT_EQ(test, flow_hash_from_keys(&keys_slow),
+			flow_hash_from_keys(&keys_fast));
+}
+
+/* Check against both eligible dissectors (different used_keys). */
+static void fd_fast_check_equiv(struct kunit *test, const u8 *data,
+				__be16 proto, int hlen, unsigned int flags)
+{
+	/* skb_get_hash() passes STOP_AT_FLOW_LABEL on every dissect; each
+	 * case must hold with and without it.
+	 */
+	unsigned int fl = flags | FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL;
+
+	fd_check_one(test, &flow_keys_dissector, data, proto, hlen, flags);
+	fd_check_one(test, flow_keys_dissector_symmetric_kunit(),
+		     data, proto, hlen, flags);
+	fd_check_one(test, &flow_keys_dissector, data, proto, hlen, fl);
+	fd_check_one(test, flow_keys_dissector_symmetric_kunit(),
+		     data, proto, hlen, fl);
+}
+
+static void fd_fast_equiv_test(struct kunit *test)
+{
+	const struct fd_fast_case *c = test->param_value;
+	u8 *buf;
+	int len;
+
+	buf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+
+	len = c->build(buf);
+	KUNIT_ASSERT_LE(test, len, FD_TEST_BUF_LEN);
+
+	fd_fast_check_equiv(test, buf, c->proto, len, c->flags);
+}
+
+/* Truncation sweep: the fast path must never parse (or partially
+ * write) anything the slow path rejected at the same length.
+ */
+static void fd_fast_truncation_test(struct kunit *test)
+{
+	int i, len, hlen;
+	u8 *buf;
+
+	buf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+
+	for (i = 0; i < ARRAY_SIZE(fd_fast_cases); i++) {
+		const struct fd_fast_case *c = &fd_fast_cases[i];
+
+		len = c->build(buf);
+		for (hlen = len - 1; hlen >= 0; hlen--)
+			fd_fast_check_equiv(test, buf, c->proto, hlen,
+					    c->flags);
+	}
+}
+
+/* skb-mode builder (for hw-accel VLAN entry conditions). */
+static struct sk_buff *fd_fast_build_skb(struct kunit *test,
+					 int (*build)(u8 *buf),
+					 __be16 protocol)
+{
+	struct sk_buff *skb;
+	int len;
+	u8 *buf;
+
+	buf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+	len = build(buf);
+
+	skb = alloc_skb(FD_TEST_BUF_LEN + NET_SKB_PAD, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, skb);
+	skb_reserve(skb, NET_SKB_PAD);
+	skb_put_data(skb, buf, len);
+	skb->protocol = protocol;
+	skb_reset_mac_header(skb);
+	skb_reset_network_header(skb);
+	return skb;
+}
+
+static void fd_check_one_skb(struct kunit *test, struct flow_dissector *fd,
+			     struct sk_buff *skb)
+{
+	struct flow_keys keys_slow, keys_fast;
+	bool ret_slow, ret_fast;
+
+	fd_fast_gates_set(false);
+	memset(&keys_slow, 0, sizeof(keys_slow));
+	ret_slow = __skb_flow_dissect(&init_net, skb, fd,
+				      &keys_slow, NULL, 0, 0, 0, 0);
+
+	fd_fast_gates_set(true);
+	memset(&keys_fast, 0, sizeof(keys_fast));
+	ret_fast = __skb_flow_dissect(&init_net, skb, fd,
+				      &keys_fast, NULL, 0, 0, 0, 0);
+	fd_fast_gates_set(false);
+
+	KUNIT_EXPECT_EQ(test, ret_slow, ret_fast);
+	KUNIT_EXPECT_MEMEQ(test, &keys_slow, &keys_fast, sizeof(keys_slow));
+	KUNIT_EXPECT_EQ(test, flow_hash_from_keys(&keys_slow),
+			flow_hash_from_keys(&keys_fast));
+}
+
+static void fd_fast_check_equiv_skb(struct kunit *test, struct sk_buff *skb)
+{
+	fd_check_one_skb(test, &flow_keys_dissector, skb);
+	fd_check_one_skb(test, flow_keys_dissector_symmetric_kunit(), skb);
+}
+
+static void fd_fast_skb_plain_test(struct kunit *test)
+{
+	struct sk_buff *skb;
+
+	skb = fd_fast_build_skb(test, build_ipv4_tcp, htons(ETH_P_IP));
+	fd_fast_check_equiv_skb(test, skb);
+	kfree_skb(skb);
+}
+
+static void fd_fast_skb_hwaccel_vlan_test(struct kunit *test)
+{
+	struct sk_buff *skb;
+
+	/* Plain payload; VLAN tag in skb metadata, as after hw stripping. */
+	skb = fd_fast_build_skb(test, build_ipv4_tcp, htons(ETH_P_IP));
+	__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), 100);
+	fd_fast_check_equiv_skb(test, skb);
+	kfree_skb(skb);
+}
+
+static void fd_fast_skb_hwaccel_vlan_qinq_test(struct kunit *test)
+{
+	struct sk_buff *skb;
+
+	/* Outer tag hw-stripped (8021AD), second tag in the payload. */
+	skb = fd_fast_build_skb(test, build_vlan_ipv4_tcp, htons(ETH_P_8021Q));
+	__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021AD), 100);
+	fd_fast_check_equiv_skb(test, skb);
+	kfree_skb(skb);
+}
+
+/* Nested tunnels: both paths must stop at MAX_FLOW_DISSECT_HDRS --
+ * shallow stacks descend, past the cap the fast path defers and
+ * matches the slow path's capped result.
+ */
+static void fd_fast_deep_nest_test(struct kunit *test)
+{
+	int levels, len;
+	u8 *buf;
+
+	buf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+
+	for (levels = 1; levels <= 24; levels++) {
+		len = build_ipip_nest(buf, levels);
+		if (len > FD_TEST_BUF_LEN)
+			break;
+		fd_fast_check_equiv(test, buf, htons(ETH_P_IP), len, 0);
+	}
+	for (levels = 1; levels <= 16; levels++) {
+		len = build_gre_nest(buf, levels);
+		if (len > FD_TEST_BUF_LEN)
+			break;
+		fd_fast_check_equiv(test, buf, htons(ETH_P_IP), len, 0);
+	}
+}
+
+/* Non-linear skb: the fast path reads only the linear head and must
+ * defer; the slow path pulls from the frag. Output must match.
+ */
+static void fd_fast_nonlinear_skb_test(struct kunit *test)
+{
+	const int linear = 8;
+	struct sk_buff *skb;
+	struct page *page;
+	u8 *buf;
+	int len;
+
+	buf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+	len = build_ipv4_tcp(buf);
+
+	skb = alloc_skb(NET_SKB_PAD + linear, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, skb);
+	skb_reserve(skb, NET_SKB_PAD);
+	skb_put_data(skb, buf, linear);
+
+	page = alloc_page(GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, page);
+	memcpy(page_address(page), buf + linear, len - linear);
+	skb_add_rx_frag(skb, 0, page, 0, len - linear, len - linear);
+
+	skb->protocol = htons(ETH_P_IP);
+	skb_reset_mac_header(skb);
+	skb_reset_network_header(skb);
+
+	fd_fast_check_equiv_skb(test, skb);
+	kfree_skb(skb);
+}
+
+/* An ineligible (custom) dissector: the fast path must never run,
+ * so gates-on output equals gates-off for the whole corpus.
+ */
+static void fd_fast_ineligible_dissector_test(struct kunit *test)
+{
+	static const struct flow_dissector_key keys[] = {
+		{ .key_id = FLOW_DISSECTOR_KEY_CONTROL,
+		  .offset = offsetof(struct flow_keys, control) },
+		{ .key_id = FLOW_DISSECTOR_KEY_BASIC,
+		  .offset = offsetof(struct flow_keys, basic) },
+		{ .key_id = FLOW_DISSECTOR_KEY_IPV4_ADDRS,
+		  .offset = offsetof(struct flow_keys, addrs.v4addrs) },
+		{ .key_id = FLOW_DISSECTOR_KEY_IPV6_ADDRS,
+		  .offset = offsetof(struct flow_keys, addrs.v6addrs) },
+		{ .key_id = FLOW_DISSECTOR_KEY_PORTS,
+		  .offset = offsetof(struct flow_keys, ports) },
+		{ .key_id = FLOW_DISSECTOR_KEY_ICMP,
+		  .offset = offsetof(struct flow_keys, icmp) },
+	};
+	struct flow_dissector custom;
+	int i, len;
+	u8 *buf;
+
+	skb_flow_dissector_init(&custom, keys, ARRAY_SIZE(keys));
+
+	buf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+
+	for (i = 0; i < ARRAY_SIZE(fd_fast_cases); i++) {
+		const struct fd_fast_case *c = &fd_fast_cases[i];
+
+		len = c->build(buf);
+		fd_check_one(test, &custom, buf, c->proto, len, c->flags);
+	}
+}
+
+/* skb-mode coverage for ipv6 / pppoe / mpls / gre. */
+static void fd_fast_skb_shapes_test(struct kunit *test)
+{
+	static const struct {
+		int (*build)(u8 *buf);
+		__be16 proto;
+	} cases[] = {
+		{ build_ipv6_tcp, cpu_to_be16(ETH_P_IPV6) },
+		{ build_pppoe_ipv4_tcp, cpu_to_be16(ETH_P_PPP_SES) },
+		{ build_mpls_ipv4, cpu_to_be16(ETH_P_MPLS_UC) },
+		{ build_gre_ipv4, cpu_to_be16(ETH_P_IP) },
+	};
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(cases); i++) {
+		struct sk_buff *skb;
+
+		skb = fd_fast_build_skb(test, cases[i].build, cases[i].proto);
+		fd_fast_check_equiv_skb(test, skb);
+		kfree_skb(skb);
+	}
+}
+
+/* Seeded, reproducible fuzzer: mutate corpus packets and lengths,
+ * assert equivalence each iteration -- the guard for divergences the
+ * hand-written corpus does not name.
+ */
+static void fd_fast_fuzz_test(struct kunit *test)
+{
+	struct rnd_state rnd;
+	u8 *buf;
+	int i;
+
+	buf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+	prandom_seed_state(&rnd, 0x1a2b3c4d5e6f7788ULL);
+
+	for (i = 0; i < FD_FUZZ_ITERS; i++) {
+		const struct fd_fast_case *c;
+		unsigned int flags;
+		int len, j, nmut;
+
+		c = &fd_fast_cases[prandom_u32_state(&rnd) %
+				   ARRAY_SIZE(fd_fast_cases)];
+		len = c->build(buf);
+
+		/* Mutate a handful of header bytes to random values. */
+		nmut = prandom_u32_state(&rnd) % (len + 1);
+		for (j = 0; j < nmut; j++)
+			buf[prandom_u32_state(&rnd) % len] =
+				prandom_u32_state(&rnd);
+
+		/* Random truncation and random 1st-frag flag. */
+		len = prandom_u32_state(&rnd) % (len + 1);
+		flags = (prandom_u32_state(&rnd) & 1) ?
+			FLOW_DISSECTOR_F_PARSE_1ST_FRAG : 0;
+
+		fd_fast_check_equiv(test, buf, c->proto, len, flags);
+	}
+}
+
+/* Gates off: the fast path must never run (counters are the
+ * observable). Positive controls: an eligible shape must count with
+ * the gates on.
+ */
+static void fd_fast_gates_off_test(struct kunit *test)
+{
+	struct flow_keys keys;
+	u64 before;
+	int i, len;
+	u8 *buf;
+
+	buf = kunit_kzalloc(test, FD_TEST_BUF_LEN, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
+
+	fd_fast_gates_set(false);
+	before = flow_dissector_fast_hits_kunit();
+	for (i = 0; i < ARRAY_SIZE(fd_fast_cases); i++) {
+		len = fd_fast_cases[i].build(buf);
+		memset(&keys, 0, sizeof(keys));
+		__skb_flow_dissect(&init_net, NULL, &flow_keys_dissector,
+				   &keys, buf, fd_fast_cases[i].proto, 0,
+				   len, fd_fast_cases[i].flags);
+	}
+	KUNIT_EXPECT_EQ(test, flow_dissector_fast_hits_kunit(), before);
+
+	fd_fast_gates_set(true);
+	len = build_ipv4_tcp(buf);
+	memset(&keys, 0, sizeof(keys));
+	__skb_flow_dissect(&init_net, NULL, &flow_keys_dissector, &keys,
+			   buf, htons(ETH_P_IP), 0, len, 0);
+	KUNIT_EXPECT_GT(test, flow_dissector_fast_hits_kunit(), before);
+
+	/* Flagship consumer shape: skb_get_hash() passes STOP_AT_FLOW_LABEL;
+	 * the fast path must hit for it.
+	 */
+	before = flow_dissector_fast_hits_kunit();
+	memset(&keys, 0, sizeof(keys));
+	__skb_flow_dissect(&init_net, NULL, &flow_keys_dissector, &keys,
+			   buf, htons(ETH_P_IP), 0, len,
+			   FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL);
+	fd_fast_gates_set(false);
+	KUNIT_EXPECT_GT(test, flow_dissector_fast_hits_kunit(), before);
+}
+
+static void fd_all_gates_off(void)
+{
+	fd_fast_gates_set(false);
+}
+
+static int fd_fast_suite_init(struct kunit_suite *suite)
+{
+	fd_all_gates_off();
+	return 0;
+}
+
+static void fd_fast_suite_exit(struct kunit_suite *suite)
+{
+	fd_all_gates_off();
+}
+
+static struct kunit_case fd_fast_test_cases[] = {
+	KUNIT_CASE_PARAM(fd_fast_equiv_test, fd_fast_gen_params),
+	KUNIT_CASE(fd_fast_truncation_test),
+	KUNIT_CASE(fd_fast_deep_nest_test),
+	KUNIT_CASE(fd_fast_nonlinear_skb_test),
+	KUNIT_CASE(fd_fast_ineligible_dissector_test),
+	KUNIT_CASE(fd_fast_skb_plain_test),
+	KUNIT_CASE(fd_fast_skb_hwaccel_vlan_test),
+	KUNIT_CASE(fd_fast_skb_hwaccel_vlan_qinq_test),
+	KUNIT_CASE(fd_fast_skb_shapes_test),
+	KUNIT_CASE(fd_fast_fuzz_test),
+	KUNIT_CASE(fd_fast_gates_off_test),
+	{}
+};
+
+static struct kunit_suite fd_fast_suite = {
+	.name = "flow_dissector_fastpath",
+	.suite_init = fd_fast_suite_init,
+	.suite_exit = fd_fast_suite_exit,
+	.test_cases = fd_fast_test_cases,
+};
+
+kunit_test_suite(fd_fast_suite);
+
+MODULE_DESCRIPTION("KUnit fast/slow equivalence tests for the flow dissector");
+MODULE_LICENSE("GPL");

3/2 2026/07/16 04:38 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 39802
							output: 197
							thoughts: 1589
						

Thoughts:
**Fuzzing the Flow Dissector Fast Paths**

Okay, so we have this patch adding fast paths to the Linux kernel's flow dissector. My initial thought is, "Reachability and functionality, let's make sure it's doing something and doing it right." The patch touches `net/core/flow_dissector.c`, a critical component for network traffic analysis. It introduces several `flow_dissect_fast_*` functions and a main `flow_dissect_fast` function, which are gated by static keys, making them opt-in and controlled via sysctls.

Since the prompt asks about CONFIG options and functions to focus on for fuzzing, let's dive in.  First, the config options. The patch adds `CONFIG_FLOW_DISSECTOR_KUNIT_TEST`, but that's a KUnit test. We can skip that, unless we have specific directions to include KUnit tests. The other configs, from what I can tell, are standard.

Now, the juicy part: the functions themselves. The new fast paths are always compiled, and they're conditionally enabled via `static_branch_unlikely`. We want to target these fast paths for fuzzing. We have `flow_dissect_fast`, `flow_dissect_fast_ipv4`, `flow_dissect_fast_ipv6`, `flow_dissect_fast_vlan`, `flow_dissect_fast_pppoe`, `flow_dissect_fast_mpls`, `flow_dissect_fast_ipip_inner`, and `flow_dissect_fast_gre_inner`. The prompt does say to avoid hot-path functions, so I'm debating whether to include `flow_dissect_fast`. But, because it's the added function for this feature, I think it's a good candidate for fuzzing.

I'm also seeing added functions, like `proc_set_vlan_key` and `proc_set_qinq_key`, which are also worth fuzzing, given their involvement in the sysctl settings. Also, `flow_dissect_fast_is_encap` should be included.

Considering all this, here's what I'm thinking:

I'm going to set `WorthFuzzing` to `true` and generate the following `FocusSymbols`:

```json
{
  "WorthFuzzing": true,
  "FocusSymbols": [
    "flow_dissect_fast",
    "flow_dissect_fast_ipv4",
    "flow_dissect_fast_ipv6",
    "flow_dissect_fast_vlan",
    "flow_dissect_fast_pppoe",
    "flow_dissect_fast_mpls",
    "flow_dissect_fast_ipip_inner",
    "flow_dissect_fast_gre_inner",
    "proc_set_vlan_key",
    "proc_set_qinq_key",
    "flow_dissect_fast_is_encap"
  ],
  "EnableConfigs": [],
  "Reasoning": "The patch introduces opt-in fast paths for the flow dissector, which parses packet headers. This is core network logic and should be fuzzed to ensure the fast paths correctly handle various packet structures without out-of-bounds reads or other memory safety issues."
}
```

The `EnableConfigs` are left empty, as the fast paths are compiled in and enabled by sysctls, which syzkaller can configure. We'll also be sure to test the newly exposed sysctls. This is a solid approach to ensure the new fast paths are robust.



4/2 2026/07/16 04:38 tool set-results
0m Args:
{
  "EnableConfigs": [],
  "FocusSymbols": [
    "flow_dissect_fast",
    "flow_dissect_fast_ipv4",
    "flow_dissect_fast_ipv6",
    "flow_dissect_fast_vlan",
    "flow_dissect_fast_pppoe",
    "flow_dissect_fast_mpls",
    "flow_dissect_fast_ipip_inner",
    "flow_dissect_fast_gre_inner",
    "proc_set_vlan_key",
    "proc_set_qinq_key"
  ],
  "Reasoning": "The patch introduces opt-in fast paths for the network flow dissector. This is reachable core network logic that processes untrusted packet data, making it a prime target for fuzzing to ensure memory safety and correctness of the new parsing logic.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": null,
  "FocusSymbols": [
    "flow_dissect_fast",
    "flow_dissect_fast_ipv4",
    "flow_dissect_fast_ipv6",
    "flow_dissect_fast_vlan",
    "flow_dissect_fast_pppoe",
    "flow_dissect_fast_mpls",
    "flow_dissect_fast_ipip_inner",
    "flow_dissect_fast_gre_inner",
    "proc_set_vlan_key",
    "proc_set_qinq_key"
  ],
  "Reasoning": "The patch introduces opt-in fast paths for the network flow dissector. This is reachable core network logic that processes untrusted packet data, making it a prime target for fuzzing to ensure memory safety and correctness of the new parsing logic.",
  "WorthFuzzing": true
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)