Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,10 @@ upgrade writes no dump.
`/chosen/multikernel,iommus`: the successor's kernel switches the unit
to tables of its own, with identity entries for its devices, and to the
interrupt remapping it already kept in step with the host's. A function
left untaken or live keeps the unit the dead host's.
left untaken or live keeps the unit the dead host's. Unless every unit
is claimed, no driver is probed for the adopted devices, as their
interrupts would still be remapped by the dead host's tables, and the
takeover goes on with the devices the successor already had.
5. **Network.** kmorphd restores the [network identity](#network-identity)
on the adopted NICs.
6. **CPUs and memory.** The successor computes what is takeable, the
Expand Down
19 changes: 15 additions & 4 deletions kmorphd/ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,27 +317,35 @@ static int claim_iommu(struct ops *o, uint64_t base)
return ret;
}

static void claim_iommus(struct ops *o, bool all_quiet)
/* Whether the successor now drives every unit. */
static bool claim_iommus(struct ops *o, bool all_quiet)
{
const struct rangelist *units = &o->iommus;
size_t i, claimed = 0;

if (!all_quiet) {
log_err("devices left untaken or live; %zu IOMMUs stay the dead host's",
units->count);
return;
return false;
}
for (i = 0; i < units->count; i++)
if (!claim_iommu(o, units->r[i].base))
claimed++;
log_info("claimed %zu of %zu IOMMUs", claimed, units->count);
return claimed == units->count;
}

/*
* A device that cannot be taken leaves the others and the takeover to go
* on. The bus probes no driver while the devices join, so each driver
* meets its device reset or quiesced rather than as the crash left it,
* and behind IOMMUs the successor drives.
*
* Behind an IOMMU the successor does not drive, a device's interrupts are
* remapped by the dead host's tables and never arrive, and a driver that
* waits for one in its probe never returns. So unless every unit was
* claimed, the bus goes on probing no driver, also for a module loaded
* later, and the takeover goes on with the devices the successor had.
*/
int ops_adopt_devices(struct ops *o)
{
Expand Down Expand Up @@ -369,8 +377,11 @@ int ops_adopt_devices(struct ops *o)
}

reset_devices(o->env.pci_bus, adopted, o->devices_adopted, o->env.reset_devices, counts);
if (iommus)
claim_iommus(o, !first && !counts[DEVICE_LIVE]);
if (iommus && !claim_iommus(o, !first && !counts[DEVICE_LIVE])) {
log_err("%zu adopted devices left without a driver on %s",
o->devices_adopted, o->env.pci_bus);
goto out;
}
ret = pci_set_autoprobe(o->env.pci_bus, true);
if (ret)
log_err("drivers left held off on %s: %s", o->env.pci_bus, strerror(-ret));
Expand Down
37 changes: 36 additions & 1 deletion tests/test_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,15 +674,49 @@ static void the_host_keeps_the_iommu_while_a_device_is_not_adopted(void)
CHECK(ops_adopt_devices(&o) < 0);
check_last_device_add("0000:05:00.0");
text = read_text(pci, "drivers_autoprobe");
CHECK_STREQ(text, "1");
CHECK_STREQ(text, "0");
free(text);
ops_free(&o);

put_rel(sysfs, "overlays/tx_1/status", "applied\n", 8);
remove_host_iommu();
put_rel(pci, "drivers_autoprobe", "1", 1);
put_rel(pci, "drivers_probe", "", 0);
}

/*
* 04:00.0 has no config space to quiesce it through, so the host's IOMMU
* is not claimed. A driver bound behind it would wait for interrupts that
* the dead host's tables do not deliver.
*/
static void no_driver_is_probed_behind_an_iommu_left_to_the_host(void)
{
struct ops o;
char *text;

setup_env(NULL);
put_host_iommu(0xfed90000);
CHECK_EQ(ops_init(&o, &env), 0);
mkdir_rel(pci, "devices/0000:04:00.0");
put_live_function("0000:05:00.0");

CHECK_EQ(ops_adopt_devices(&o), 0);
CHECK_EQ(o.devices_adopted, 2);
check_last_device_add("0000:05:00.0");
text = read_text(pci, "drivers_probe");
CHECK_STREQ(text, "");
free(text);
text = read_text(pci, "drivers_autoprobe");
CHECK_STREQ(text, "0");
free(text);
ops_free(&o);

remove_rel(pci, "devices/0000:04:00.0");
remove_function("0000:05:00.0");
remove_host_iommu();
put_rel(pci, "drivers_autoprobe", "1", 1);
}

TEST_MAIN({
if (!mkdtemp(root)) {
perror("mkdtemp");
Expand Down Expand Up @@ -714,4 +748,5 @@ TEST_MAIN({
RUN(without_reset_drivers_bind_as_devices_join);
RUN(quiesced_devices_let_the_successor_claim_the_iommu);
RUN(the_host_keeps_the_iommu_while_a_device_is_not_adopted);
RUN(no_driver_is_probed_behind_an_iommu_left_to_the_host);
})