[PATCH v2 0/2] lib/ts_fsm: preserve patterns across tc dump and restore
From: Zhiqi Zhang
Date: Sun Nov 01 2026 - 03:19:54 EST
Dumping and restoring a tc text ematch configured with the FSM algorithm
can change its packet matching behaviour or fail with EINVAL. This series
preserves the public token types returned by textsearch_get_pattern() and
adds regression coverage for exporting and recreating an FSM configuration.
Changes since v1:
- Describe the tc userspace impact in the fix's commit message.
- Split the production fix and KUnit tests; mark the fix for stable.
- Add KUNIT_EXPECT_MEMEQ for the exported representation, as Andrew suggested.
- Add tc maintainers and netdev to the recipients.
- Add actual loopback packet classification and performance measurements.
The production code change is identical to v1.
Validation on base 2a500a04d6f969318c05f46aedb6e73fc1963a00:
- The same updated KUnit test and ARM64 GCC configuration fail 13 of 15
tests before the fix and pass all 15 after it. ARM32 GCC and ARM64 Clang
also pass 15/15. Compilers: GCC 13.3 and Clang 18.1.3; QEMU 8.2.2.
- In an isolated ARM64 QEMU guest, a tc basic filter matches the four-byte
UDP payload "7777" and rejects "AAAA". Recreating its DIGIT/MULTI text
ematch from the rtnetlink dump makes both payloads match before the fix;
after the fix the restored rule still rejects "AAAA". Every probe is
observed in the classifier's evaluated/matched counters. Restoring a
PRINT/MULTI rule returns EINVAL before the fix and succeeds after it.
- The guests have no external NIC. These tests use direct rtnetlink,
rather than claiming coverage of a particular tc save/restore utility.
- W=1 reports no warnings for changed objects. Sparse has no diagnostics
for them; an unchanged ARM64 vDSO object has a declaration diagnostic.
A native ARM64 userspace microbenchmark of the mechanically extracted FSM
matcher (GCC 13.3, 64 paired samples per case) measured median paired
slowdowns of about 1-5% for the tested long character-class scans and
about 13% for a one-byte rejection case with appreciable variability.
These results do not establish in-kernel or network throughput. The extra
lookup trades matching cost for avoiding a second stored pattern copy.
Mainline cbbddb6b08cc9900a87cccaa9b22bbe06aa4f50a, linux-next and
mm-nonmm-unstable still have the affected code. The series applies to all
three checked heads; they were not built or booted for this revision.
No x86, big-endian, sanitizer, module-load or stable-branch runtime testing
was performed. The packet test measures matching, not dropping actions or
network throughput.
I identified the issue and reviewed, built and tested the v1 fix. OpenAI
Codex drafted the fix, tests and changelogs and drove the additional v2
validation. The added assertion and revised messages are AI-assisted.
v1: https://lore.kernel.org/all/20261031052307.23533-1-zhiqizhangg@xxxxxxxxx/
Review: https://lore.kernel.org/all/20261031202211.22f18bca7819dbe2d107d17d@xxxxxxxxxxxxxxxxxxxx/
Zhiqi Zhang (2):
lib/ts_fsm: preserve token types when exporting patterns
lib/ts_fsm: add KUnit coverage for exported patterns
lib/Kconfig.debug | 14 ++++
lib/tests/Makefile | 1 +
lib/tests/textsearch_fsm_kunit.c | 138 +++++++++++++++++++++++++++++++
lib/ts_fsm.c | 7 +-
4 files changed, 154 insertions(+), 6 deletions(-)
create mode 100644 lib/tests/textsearch_fsm_kunit.c
base-commit: 2a500a04d6f969318c05f46aedb6e73fc1963a00
--
2.54.0 (Apple Git-157)