ldls: a second driver, and everything it found
e1000 -- Linux's, unmodified -- probes, opens, gets an address by DHCP and
carries ping traffic in a SchOS process. The kernel was driving that NIC and
gave it up, which makes it the first real handover as well as the second
driver.
None of what it needed was a missing feature. Every one was a call that
succeeded, returned zero and did nothing:
_find_next_bit "bit 0 is set" -- for_each_cpu never ended
netif_carrier_off carrier already up -- TCTL.EN never set
__x86_indirect_thunk_r8 the jump discarded -- 255 rx buffers, none made
dma_map_page_attrs bus address 0 -- NIC aimed at physical 0
so the rule from memcpy is now general: a stub returning zero is unsafe
wherever zero is a meaningful answer.
The loader grew ko_fixup_percpu(). The stack guard turned out to be one
per-CPU variable among several; `current` cannot be defused because the driver
dereferences it. Taking the %gs off instead leaves the same opcode reading the
same width from storage the host supplies -- a per-CPU variable in a
single-threaded host is just a variable. Eight bytes become seven and a nop,
and the displacement is not always last, so there is now just enough of an x86
decoder in ko.c to know how long the instruction is.
ldls/kpi/thunk.c is fifteen lines of assembly and the highest-value file here:
retpolines are control flow, and a stub cannot stand in for a jump.
The kernel side:
- ioperm.c, the TSS I/O permission bitmap. A driver's outl is an instruction,
not a call, and e1000's reset path picks it deliberately. IOPL=3 would hand
over the PIC and the disk with it, so it is per-port. Writing it found that
the I/O map base had been written at offset 64 rather than 102, leaving the
CPU checking ports 0-831 against the TSS's own RSP0.
- claim masks the device's IRQ line: 450,000 a second, otherwise.
- net_detach(), the missing half of net_attach_late(). An interface left in
the stack keeps its route and sends every frame to a driver that refuses
it, which looks exactly like a userspace driver that does not work.
- e1000_release() gives up the interface, not just the hardware.
8139too still passes 4/4; ldls-check still passes 27; four CPUs, no panic.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VQ7Qx8E1q1M1bbCq8QLHS2
This commit is contained in:
parent
f38eb8a7fd
commit
071499a378
26 changed files with 2009 additions and 46 deletions
|
|
@ -78,8 +78,18 @@ struct kpi_layout {
|
|||
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 pd_dev, dev_kobj, kobj_name;
|
||||
unsigned int ndo_open, ndo_stop, ndo_start_xmit;
|
||||
|
||||
// work_struct.func -- where a deferred work item keeps the function to call.
|
||||
// `struct delayed_work` starts with a work_struct, so one offset serves both.
|
||||
unsigned int work_func;
|
||||
|
||||
// __LINK_STATE_NOCARRIER, from BTF. `netif_carrier_ok` is an inline that
|
||||
// tests this bit of net_device.state, so it is the one number that decides
|
||||
// whether a driver believes its link came up.
|
||||
unsigned int link_nocarrier;
|
||||
|
||||
unsigned int skb_size;
|
||||
unsigned int skb_len, skb_data, skb_head, skb_tail, skb_end, skb_dev;
|
||||
};
|
||||
|
|
@ -95,6 +105,29 @@ extern struct kpi_layout kpi_l;
|
|||
extern int (*kpi_napi_poll)(void *napi, int budget);
|
||||
extern void *kpi_napi;
|
||||
|
||||
// The driver's own interrupt handler, kept and called from the loop. See the
|
||||
// note in kpi.c: this is not about receiving packets, it is about everything a
|
||||
// driver only ever does from inside its handler.
|
||||
int kpi_request_irq(unsigned int irq, void *handler, void *thread_fn,
|
||||
unsigned long flags, const char *name, void *dev);
|
||||
int kpi_free_irq(unsigned int irq, void *dev);
|
||||
int kpi_irq_poll(void);
|
||||
|
||||
// A driver's deferred work, run from the same loop that polls. See work.c --
|
||||
// e1000 enables its transmitter from a watchdog, so this is not optional.
|
||||
int kpi_queue_work_on(int cpu, void *q, void *work);
|
||||
int kpi_queue_delayed_work_on(int cpu, void *q, void *dwork, unsigned long delay);
|
||||
int kpi_cancel_work_sync(void *work);
|
||||
int kpi_cancel_delayed_work_sync(void *dwork);
|
||||
int kpi_cancel_delayed_work(void *dwork);
|
||||
int kpi_flush_work(void *work);
|
||||
int kpi_work_run(void);
|
||||
|
||||
// The clock those deadlines are measured against, and the `jiffies` a driver
|
||||
// reads directly.
|
||||
extern unsigned long kpi_jiffies;
|
||||
unsigned long kpi_jiffies_now(void);
|
||||
|
||||
// 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);
|
||||
|
|
@ -105,6 +138,12 @@ void kpi_loghex(unsigned long long v, int digits);
|
|||
// default -- 538 of 8139too's 552 probe calls are ioread8/iowrite8.
|
||||
extern int kpi_verbose;
|
||||
|
||||
// Memory a device can be pointed at, in pieces smaller than a PCIIOC_DMA call.
|
||||
// The skb path uses it, because a driver that maps an skb for its device needs
|
||||
// the bus address of the data. See the long note in kpi.c.
|
||||
void *kpi_dma_heap(unsigned long n, unsigned long align);
|
||||
unsigned long long kpi_phys_of(const void *va);
|
||||
|
||||
// Is this a register address we handed out? Reports the first few that are
|
||||
// not, then goes quiet -- a driver that is off the rails produces thousands.
|
||||
int kpi_io_ok(void *addr, int width, int write);
|
||||
|
|
|
|||
Loading…
Reference in a new issue