ldls: ping, over a Linux driver
docs/plan/ldls.md L3d, and with it L3 -- the milestone the plan calls the one
that proves the whole idea and the one that cannot be skipped.
# ldlsd /lib/modules/8139too.ko /lib/modules/btf &
kpi: the driver read a MAC off the hardware: 52:54:00🆎cd:ef
ndo_open returned 0
carrying frames. the interface is ldls0.
# cat /proc/netif
interface ldls0 state up address 10.9.0.15 gateway 10.9.0.2
# ping 10.9.0.2 4
64 bytes from 10.9.0.2: icmp_seq=1 time=30 ms
64 bytes from 10.9.0.2: icmp_seq=2 time=20 ms
64 bytes from 10.9.0.2: icmp_seq=3 time=20 ms
64 bytes from 10.9.0.2: icmp_seq=4 time=20 ms
10.9.0.0/24 is reachable only through ldls0, and ldls0 is 8139too running in a
SchOS process. The address was obtained by DHCP over the same driver first.
lwIP -> netdev_ops -> /dev/netdev -> ldlsd -> ndo_start_xmit -> a BAR mapped by
/dev/pci -> the wire, and the whole way back. Nothing in the kernel knows a
Linux driver is involved; nothing in the driver knows it is not in Linux.
It polls rather than taking interrupts. /dev/pci delivers them by blocking
read(), which needs a thread this program does not have, so the driver's NAPI
poll is called from a loop instead -- the same work in a context LDLS can
provide, at the cost of latency and a spinning process.
Four things Linux's alloc_etherdev does that allocating does not, each found by
the driver faulting on it: dev->dev_addr is a pointer aimed at perm_addr;
dev->mc and dev->uc are list heads and are empty only when they point at
themselves; dev->_tx is an array of netdev_queue, because netif_start_queue
clears a bit in _tx[0].state; and __LINK_STATE_START is set by dev_open before
ndo_open is called.
Two did not announce themselves, and they are the ones worth recording.
netif_running(dev) gates 8139too's receive loop. Without it the chip received
the frame, the driver acknowledged the interrupt and left the loop, and nothing
came out -- while every counter said packets were arriving. Found by reading
the chip's own CBR register through the BAR and seeing the hardware had written
600 bytes the driver never collected.
memcpy was still a logging stub. The driver copied each frame into its sk_buff,
the copy did not happen, and the stack was handed exactly the right length of
zeroes; DHCP never completed and nothing reported an error. A stub that returns
zero is not safe for a function whose whole job is a side effect, and the
memory primitives are the worst case because they fail silently and plausibly.
ldls/kpi/string.c exists because of it.
Still one driver, one kernel version, tried once, against an emulated card --
which is what the plan has always promised and is worth repeating next to a
working ping.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VQ7Qx8E1q1M1bbCq8QLHS2
This commit is contained in:
parent
42f98130c4
commit
888c48fd96
9 changed files with 809 additions and 14 deletions
|
|
@ -67,6 +67,34 @@ struct kpi_ctx {
|
|||
|
||||
extern struct kpi_ctx kpi;
|
||||
|
||||
// The struct offsets the KPI needs at run time, read from the kernel's own BTF
|
||||
// by the host before the driver starts. See ldls/btf.h -- nothing here is
|
||||
// written down, because a compiled driver and this code have to agree about
|
||||
// them exactly and only the kernel that driver was built for can say.
|
||||
struct kpi_layout {
|
||||
unsigned int nd_netdev_ops;
|
||||
unsigned int nd_dev_addr, nd_perm_addr, nd_addr_len;
|
||||
unsigned int nd_mc, nd_uc;
|
||||
unsigned int nd_tx, nd_num_tx, nd_real_num_tx;
|
||||
unsigned int nq_size, nq_dev;
|
||||
unsigned int nd_state, nd_flags;
|
||||
unsigned int ndo_open, ndo_stop, ndo_start_xmit;
|
||||
|
||||
unsigned int skb_size;
|
||||
unsigned int skb_len, skb_data, skb_head, skb_tail, skb_end, skb_dev;
|
||||
};
|
||||
|
||||
extern struct kpi_layout kpi_l;
|
||||
|
||||
// The driver's NAPI poll, captured when it registers one.
|
||||
//
|
||||
// A NAPI driver does almost nothing in its interrupt handler: it schedules,
|
||||
// and the receive happens later in the poll. LDLS has no softirq to run that
|
||||
// from, so it keeps the function pointer and calls it from its own loop --
|
||||
// which is what a poll loop is, arrived at from the other direction.
|
||||
extern int (*kpi_napi_poll)(void *napi, int budget);
|
||||
extern void *kpi_napi;
|
||||
|
||||
// Output. The KPI is inside a process with no libc, and every implementation
|
||||
// wants to be able to say what it did.
|
||||
void kpi_log(const char *s);
|
||||
|
|
|
|||
Loading…
Reference in a new issue