From 47d1161ec55b2843b1c3f220dee6968c76a99f43 Mon Sep 17 00:00:00 2001 From: Cong Wang Date: Wed, 2 Dec 2026 15:48:56 -0800 Subject: [PATCH] kmorphd: Probe no driver behind an IOMMU that was not claimed A successor that does not come to drive the dead host's IOMMUs went on to probe drivers for the devices it adopted. Their interrupts are still remapped by the host's tables, so they never arrive: virtio_blk waits for its first read forever inside its probe, and kmorphd with it. The takeover stays at FENCED. That is the case whenever a device could be neither taken nor quiesced, since kmorphd then leaves every unit to the dead host on purpose, and whenever the kernel refuses a claim. Unless every unit is claimed, leave the adopted devices without a driver and finish the takeover with the CPUs, the memory and the devices the successor already had. The bus is left probing no driver, so that a module loaded later does not bind one of them and block the same way. Signed-off-by: Cong Wang --- README.md | 5 ++++- kmorphd/ops.c | 19 +++++++++++++++---- tests/test_ops.c | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0ed0d13..c8d187f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/kmorphd/ops.c b/kmorphd/ops.c index 11d46b3..33a779d 100644 --- a/kmorphd/ops.c +++ b/kmorphd/ops.c @@ -317,7 +317,8 @@ 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; @@ -325,12 +326,13 @@ static void claim_iommus(struct ops *o, bool all_quiet) 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; } /* @@ -338,6 +340,12 @@ static void claim_iommus(struct ops *o, bool all_quiet) * 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) { @@ -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)); diff --git a/tests/test_ops.c b/tests/test_ops.c index a2181ee..2997a38 100644 --- a/tests/test_ops.c +++ b/tests/test_ops.c @@ -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"); @@ -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); })