Commit Graph
8 Commits
Author SHA1 Message Date
Brad Fitzpatrick 06bdac96d3 kernel/linux/{DESIGN.md,scripts}: record the performance work, add leancompare.sh
DESIGN.md's Performance section now describes what tswg changes in the
data path and why, the results against wireguard-go (parity to 1.05x on
bulk TCP at 6-10% less CPU per byte, much better small-packet delivery,
worse idle and p99-under-load latency in VMs) and the tools for this
work. The TODO list gets the open performance items.

leancompare.sh runs the lean harness's interleaved A/B comparison for
RTT and TCP with 1 and 4 streams.

Updates #426

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: Icf8c7ca8bb3711a8172284382af9ce8c3e25ff3d
2026-11-07 14:38:57 +00:00
Brad Fitzpatrick 9dc696cc4d kernel/linux/{scripts,src}: add a KASAN/lockdep debug kernel, and rename slab caches
gokrazy-debug-kernel.sh builds the gokrazy kernel package's kernel again
with KASAN, lockdep, DEBUG_VM and DEBUG_NET, for tailscale.com's lean
harness to boot (TSWG_DEBUG_KERNEL=1). build-for-gokrazy.sh builds
against it when given TSWG_KDIR, since those options change kernel data
structures.

Its first find: our slab caches had upstream WireGuard's names (via
KMEM_CACHE), which clash with wireguard.ko or a built-in WireGuard, as
gokrazy has, and make slab_common warn at load. Give them tswg_ names.

Updates #426

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I2e7d5448bcf8b2fb68810486f7e5d4bf2af4558d
2026-11-07 13:29:15 +00:00
Brad Fitzpatrick 7648a28d11 kernel/linux/{scripts,DESIGN.md}: add leanbench.sh and record lean benchmark results
leanbench.sh runs tailscale.com's new lean data plane benchmark, which
compares wireguard-go, tswg, the kernel's WireGuard and no tunnel between
two QEMU VMs on a host bridge with vhost-net, without natlab, over IPv4
and IPv6. With -smoke it runs the quick correctness test instead.

The results overturn the natlab ones, which natlab's userspace network
had capped: kernel WireGuard (and tswg, identically) gets about a third
of wireguard-go's bulk TCP throughput, at 1.5x to 2.5x the CPU per byte,
without being CPU-bound. So outer UDP GSO/GRO and finding where the
kernel serializes are now the critical performance work.

Updates #426

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I2a24de8d82370fc8dfb6a9af0971da20831ea307
2026-11-07 06:06:16 +00:00
Brad Fitzpatrick ac26c5bfce kernel/linux/{scripts,DESIGN.md}: add bench.sh and record first natlab benchmarks
bench.sh runs tailscale.com's TestTSWGBenchmark, which compares
tailscaled in kernel mode against tailscaled in TUN mode (wireguard-go)
on the same pair of natlab gokrazy VMs, and saves the results as JSON.

Record the first results: bulk TCP throughput and CPU per byte are about
the same (natlab caps throughput, and the kernel lacks outer UDP
GSO/GRO), while the kernel receives about 1.7x the small packets per
second at about 30% less CPU per packet and roughly halves latency under
load. Also record the plan for a lean benchmark harness without natlab,
whose userspace switch is expensive, and a flake seen when both peers
restart at once.

Updates #426

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I69e696817f98e685576a30d766c42740d4d04810
2026-11-07 05:52:04 +00:00
Brad Fitzpatrick 309157b88f kernel/linux/scripts: build tswg.ko for gokrazy kernels
The natlab gokrazy image runs a recent upstream kernel (7.2.8 today) that
gokrazy rebuilds and tailscale.com bumps regularly, which makes it a
better primary test target than a distro kernel: it keeps us honest
against new kernel APIs, and gokrazy has no userspace tools, as in the
end state where tailscaled drives the kernel entirely.

gokrazy kernels are kernel.org releases plus the patches in
_build/series, built with an embedded config and without MODVERSIONS or
module signing. gokrazy-kdir.sh downloads the release, applies the
patches, installs the config pulled out of vmlinuz with the kernel's
extract-ikconfig (vendored), and runs modules_prepare, caching the
result by release and config hash. It takes about 20 seconds the first
time. The only config differences after olddefconfig with the host's gcc
13 (gokrazy uses Debian 12's gcc 12) are toolchain capability bits.

Factor the generic part of build-for-ubuntu.sh into build.sh, which now
copies only sources (not objects from an in-place build in src/), and
sets KBUILD_MODPOST_WARN=1 for trees without a Module.symvers. Add
build-for-gokrazy.sh.

Updates #426

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: Id28d9c013bdfaa7cec28aeff846f7f6087e25518
2026-11-06 21:44:29 +00:00
Brad Fitzpatrick 370c6a69ea kernel/linux/scripts: add build-for-ubuntu.sh and vmtest.sh
build-for-ubuntu.sh builds tswg.ko for a given Ubuntu kernel release in a
private copy of src/, so test builds for different guest kernels don't
share object files with each other or with a developer's in-place build.
The Makefile's SRC is now overridable to allow that.

vmtest.sh runs the tswg natlab vmtests, which live in a tailscale.com
checkout (on the bradfitz/tswg branch) because they use its natlab
framework and the Go tswg netlink client there.

Updates #426

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I00eb5cbf8df5a203d6d39d541779060db74da9a1
2026-11-06 21:06:08 +00:00
Brad Fitzpatrick ff6f9e8409 kernel/linux/{src/compat,scripts}: add feature-probe compat layer for 6.8 and 7.0
The fork tracks the newest upstream WireGuard (7.4-rc1), but has to build
on distro kernels. Our first target is the natlab Ubuntu 24.04 guest
(6.8.0-106-generic) and the dev host is on 7.0.

Rather than LINUX_VERSION_CODE checks, which lie on heavily backported
kernels such as RHEL's, scripts/probe.sh compile-tests each
src/compat/probes/HAVE_*.c against the target kernel's build directory
(in parallel, about one second in total) and writes
src/compat/generated/autoconf.h. Kbuild force-includes src/compat/compat.h,
which shims whatever is missing: udp_get_len_short, the struct sock
udp_tunnel APIs, the ipcb_flags xmit arguments, the blake2s_ctx API,
WQ_PERCPU, netif_threaded_enable, rtnl_newlink_params, sockaddr_inet, the
kmalloc_obj family and timer_container_of.

Three spots in device.c can't be shimmed from a header (the lltx bit, the
old rtnl newlink signature, and pernet exit_rtnl) and get small #ifdefs
marked TSWG_COMPAT. device.c also always sets ndo_get_stats64 to
dev_get_tstats64, since older kernels don't fold tstats in
dev_get_stats(). That is equivalent on new kernels.

tswg.ko now builds against both 6.8.0-106-generic and 7.0.0-1009-aws.

Updates #426

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: I0ed279318b4f623688d1f178a9b8fbcc0b585219
2026-11-06 21:01:41 +00:00
Brad Fitzpatrick af92b849a7 kernel/linux/src: fork WireGuard as the out-of-tree tswg module
Copy upstream/drivers/net/wireguard into src and rename only the
user-visible identifiers: the module (and thus the rtnl link kind and
device type, which come from KBUILD_MODNAME) is now tswg, and the
genetlink family is "tswg". The uapi header moves to
src/include/uapi/linux/tswg.h so it can't collide with the kernel's.
Internal wg_ symbols keep their names to keep upstream merges easy; they
aren't exported, so tswg.ko can coexist with wireguard.ko.

Add an out-of-tree Kbuild and top-level Makefile, plus
scripts/ubuntu-headers.sh, which fetches and unpacks an Ubuntu kernel's
headers so we can build for the natlab Ubuntu guest without installing
anything.

This still only builds against 7.4-era kernels; compat shims follow.

Updates #426

Signed-off-by: Brad Fitzpatrick <[email protected]>
Change-Id: Ia36ef82a53efbbcdb301ed069785162372efda55
2026-11-06 20:55:25 +00:00