From a50a08875aa81efd3a81abe21df97b783c6d64bf Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 07:09:17 +1100 Subject: [PATCH 1/2] iommu: apple-dart: name the live-leaf protection after what it does The t8132_dcp_v27 flag selects one thing: re-exported firmware segments take the protection of the live leaves that map them (__apple_dart_t8132_dcp_v27_fw_prot()). Nothing in that helper is specific to one SoC or firmware build. It reads the DART's own locked root and leaves a region alone unless every page's live leaf maps exactly that address with one protection. Rename the flag to fw_live_prot and the helper to __apple_dart_fw_live_prot(), so it can be set for other locked display DARTs. The selection of the 27.2 internal display DARTs (apple_dart_serves_t8132_dcp_v27()) keeps its name. No functional change. Signed-off-by: Ryan Murray --- drivers/iommu/apple-dart-test.c | 23 ++++++++++++----------- drivers/iommu/apple-dart.c | 27 ++++++++++++++------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/drivers/iommu/apple-dart-test.c b/drivers/iommu/apple-dart-test.c index 920097ea03f70..2a7b21231d723 100644 --- a/drivers/iommu/apple-dart-test.c +++ b/drivers/iommu/apple-dart-test.c @@ -1347,11 +1347,12 @@ static u64 *apple_dart_test_reserved_table(struct kunit *test) } /* - * A 27.2 T8132 internal display DART: re-exported firmware segments take the - * protection of the live leaves that map them (read-only text, cacheable - * data); a region whose leaf maps another page keeps what it asked for. + * A display DART with locked roots (fw_live_prot): re-exported firmware + * segments take the protection of the live leaves that map them (read-only + * text, cacheable data); a region whose leaf maps another page keeps what it + * asked for. */ -static void apple_dart_test_t8132_dcp_v27_fw_prot(struct kunit *test) +static void apple_dart_test_fw_live_prot(struct kunit *test) { const u64 fields = GENMASK_ULL(51, 40) | BIT_ULL(0); const phys_addr_t text_pa = 0x80000000ULL, data_pa = 0x80100000ULL; @@ -1379,7 +1380,7 @@ static void apple_dart_test_t8132_dcp_v27_fw_prot(struct kunit *test) dart->oas = 42; dart->locked = true; dart->fw_mirror = true; - dart->t8132_dcp_v27 = true; + dart->fw_live_prot = true; /* The display DARTs' window: 64 GiB at 1 TiB. */ dart->locked_window[23] = 0x10000000000ULL; root = apple_dart_test_reserved_table(test); @@ -1416,7 +1417,7 @@ static void apple_dart_test_t8132_dcp_v27_fw_prot(struct kunit *test) pm_runtime_set_active(dart->dev); pm_runtime_enable(dart->dev); - __apple_dart_t8132_dcp_v27_fw_prot(&master, dart->dev, &head); + __apple_dart_fw_live_prot(&master, dart->dev, &head); KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_CACHE); KUNIT_EXPECT_EQ(test, data.prot, IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE); KUNIT_EXPECT_EQ(test, moved.prot, IOMMU_READ | IOMMU_WRITE); @@ -1426,21 +1427,21 @@ static void apple_dart_test_t8132_dcp_v27_fw_prot(struct kunit *test) /* A leaf table outside reserved RAM is never mapped: nothing changes. */ text.prot = IOMMU_READ | IOMMU_WRITE; ClearPageReserved(virt_to_page(leaf)); - __apple_dart_t8132_dcp_v27_fw_prot(&master, dart->dev, &head); + __apple_dart_fw_live_prot(&master, dart->dev, &head); SetPageReserved(virt_to_page(leaf)); KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); /* A four-level root is not walked: nothing changes. */ text.prot = IOMMU_READ | IOMMU_WRITE; writel(dart->hw->tcr_4level, dart->regs + DART_TCR(dart, 23)); - __apple_dart_t8132_dcp_v27_fw_prot(&master, dart->dev, &head); + __apple_dart_fw_live_prot(&master, dart->dev, &head); writel(0, dart->regs + DART_TCR(dart, 23)); KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); /* Not a 27.2 T8132 internal display DART: nothing changes. */ text.prot = IOMMU_READ | IOMMU_WRITE; - dart->t8132_dcp_v27 = false; - __apple_dart_t8132_dcp_v27_fw_prot(&master, dart->dev, &head); + dart->fw_live_prot = false; + __apple_dart_fw_live_prot(&master, dart->dev, &head); KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); pm_runtime_disable(dart->dev); } @@ -1454,7 +1455,7 @@ static struct kunit_case apple_dart_test_cases[] = { KUNIT_CASE(apple_dart_test_locked_handoff), KUNIT_CASE(apple_dart_test_sync_unknown_roots), KUNIT_CASE(apple_dart_test_firmware_roots), - KUNIT_CASE(apple_dart_test_t8132_dcp_v27_fw_prot), + KUNIT_CASE(apple_dart_test_fw_live_prot), KUNIT_CASE(apple_dart_test_unmap_flush_after_publish_failure), KUNIT_CASE(apple_dart_test_gated_commands), KUNIT_CASE(apple_dart_test_resume_commands_failure), diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index bc582e3facb51..bd0f8640ed6ff 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -426,8 +426,8 @@ struct apple_dart { u32 sleep_gated : 1; /* Locked roots may hold firmware slots that mirror Linux mappings. */ u32 fw_mirror : 1; - /* A T8132 internal display DART on the 27.2 image (fw_mirror, not borrowed). */ - u32 t8132_dcp_v27 : 1; + /* Re-exported firmware segments take their live leaves' protection. */ + u32 fw_live_prot : 1; /* * fw_mirror's four-level locked roots hold firmware's own subtrees, which * are recorded and reserved (apple_dart_snapshot_fw_tree()). Set only for @@ -4565,18 +4565,19 @@ static void apple_dart_get_fw_resv_regions(struct device *dev, } /* - * A T8132 internal display DART on the 27.2 image (fw_mirror): the boot loader - * re-exports the firmware's own segments as iommu-addresses, which the core - * maps read-write, and uncached for this non-coherent DCP. The firmware's - * leaves say what those pages are: its text read-only, all of it cacheable. + * A display DART with locked roots (fw_mirror, fw_live_prot), such as a T8132 + * internal display DART on the 27.2 image: the boot loader re-exports the + * firmware's own segments as iommu-addresses, which the core maps read-write, + * and uncached for this non-coherent DCP. The firmware's leaves say what + * those pages are: its text read-only, all of it cacheable. * A Linux table in a slot the firmware holds must mirror its leaves exactly * (apple_dart_fw_slot_mirrors()), so give each such region the protection the * live leaves give every one of its pages. A region whose pages are not mapped * there, map elsewhere or disagree keeps its protection, and the attach then * refuses it as before. */ -static void __apple_dart_t8132_dcp_v27_fw_prot(struct apple_dart_master_cfg *cfg, - struct device *dev, struct list_head *head) +static void __apple_dart_fw_live_prot(struct apple_dart_master_cfg *cfg, + struct device *dev, struct list_head *head) { const int mask = IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE; struct iommu_resv_region *region; @@ -4590,7 +4591,7 @@ static void __apple_dart_t8132_dcp_v27_fw_prot(struct apple_dart_master_cfg *cfg if (!cfg || !cfg->stream_maps[0].dart || cfg->stream_maps[1].dart) return; dart = cfg->stream_maps[0].dart; - if (!dart->t8132_dcp_v27 || !dart->locked || dart->hw->fmt != APPLE_DART2) + if (!dart->fw_live_prot || !dart->locked || dart->hw->fmt != APPLE_DART2) return; entries = dart->pgsize / sizeof(u64); sid = find_first_bit(cfg->stream_maps[0].sidmap, dart->num_streams); @@ -4666,9 +4667,9 @@ static void __apple_dart_t8132_dcp_v27_fw_prot(struct apple_dart_master_cfg *cfg memunmap(root); } -static void apple_dart_t8132_dcp_v27_fw_prot(struct device *dev, struct list_head *head) +static void apple_dart_fw_live_prot(struct device *dev, struct list_head *head) { - __apple_dart_t8132_dcp_v27_fw_prot(dev_iommu_priv_get(dev), dev, head); + __apple_dart_fw_live_prot(dev_iommu_priv_get(dev), dev, head); } static void apple_dart_get_resv_regions(struct device *dev, @@ -4700,7 +4701,7 @@ static void apple_dart_get_resv_regions(struct device *dev, /* Keep the translated-domain requirement and inherited translations. */ iommu_dma_get_resv_regions(dev, head); - apple_dart_t8132_dcp_v27_fw_prot(dev, head); + apple_dart_fw_live_prot(dev, head); apple_dart_get_fw_resv_regions(dev, head); } @@ -6066,7 +6067,7 @@ static int apple_dart_probe(struct platform_device *pdev) dev_err(dev, "T8132 internal display DART on the 27.2 image: NOT locked: refusing\n"); else if (t8132_display_v27) dev_err(dev, "T8132 internal display DART on the 27.2 image: locked with a reserved-table handoff: refusing\n"); - dart->t8132_dcp_v27 = t8132_display_v27; + dart->fw_live_prot = t8132_display_v27; if (t8132_display_v27 && !dart->fw_mirror) { ret = -EINVAL; goto err_clk_disable; From 1651b82700d74fe31bf57d6a5a72cb37d5faa0c7 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 02:26:04 +1100 Subject: [PATCH 2/2] iommu: apple-dart: keep the firmware roots of any locked T8132 DART A T8132 DART kept its firmware's locked roots (fw_mirror) only when it served an internal display processor handed over with the 27.2 image, so the J773g's dcpext0 DARTs, which the 27.2 boot loader also leaves locked, took the plain locked path and lost the firmware's root slots. Keying them on the dcpext's firmware version and image UUID instead would tie the choice to one macOS build. Whether the roots must be kept is visible on the DART itself: it is locked and there is no reserved-table handoff. The T6041, T6050, T8140 and T8142 DARTs already decide that way. Do the same for apple,t8132-dart, keeping out only the display DARTs borrowed on the 26.6.2 path (preserve_display), which keep their own handling. A T8132 fw_mirror DART also gets the live-leaf protection for its re-exported firmware segments (fw_live_prot); __apple_dart_fw_live_prot() changes a region only where every page's live leaf maps exactly that address with one protection. The other SoCs keep their current protection. An unlocked T8132 DART now takes the plain path like an unlocked DART on any other SoC, as it did before for everything but the 27.2 internal display DARTs. Those are still refused when unlocked: they are selected by their processor's handoff, which implies a lock. The 27.2 internal display DARTs take the same path as before: mirrored when locked, refused when unlocked or handed over with reserved tables. Any other locked T8132 DART logs "T8132 DART locked by the boot loader: locked roots kept (mirror)", so a boot shows which DARTs the rule picks. KUnit: the selection for locked, unlocked, handed-off and borrowed T8132 DARTs, the other mirrored SoCs, and two SoCs outside the rule. Signed-off-by: Ryan Murray --- drivers/iommu/apple-dart-test.c | 72 +++++++++++++++++++++++++++++++++ drivers/iommu/apple-dart.c | 53 ++++++++++++++++++------ 2 files changed, 113 insertions(+), 12 deletions(-) diff --git a/drivers/iommu/apple-dart-test.c b/drivers/iommu/apple-dart-test.c index 2a7b21231d723..e9825d632df46 100644 --- a/drivers/iommu/apple-dart-test.c +++ b/drivers/iommu/apple-dart-test.c @@ -1446,6 +1446,77 @@ static void apple_dart_test_fw_live_prot(struct kunit *test) pm_runtime_disable(dart->dev); } +/* A device node with only a compatible list, as of_device_is_compatible() reads it. */ +struct apple_dart_test_node { + struct property compatible; + struct device_node np; +}; + +static void apple_dart_test_node(struct apple_dart_test_node *node, const char *compat, + size_t len) +{ + *node = (struct apple_dart_test_node){ + .compatible = { .name = "compatible", .length = len, .value = (void *)compat }, + }; + node->np.properties = &node->compatible; +} + +#define APPLE_DART_TEST_NODE(node, compat) \ + apple_dart_test_node(node, compat, sizeof(compat)) + +/* + * fw_mirror follows the DART's own state: any locked T8132 DART without a + * reserved-table handoff that is not borrowed keeps its firmware's roots, as + * T6041/T6050/T8140/T8142 ones do, whatever the board or firmware build. + * fw_live_prot comes with it on T8132 only. + */ +static void apple_dart_test_keeps_fw_roots(struct kunit *test) +{ + static const char *const mirrored[] = { + "apple,t6041-dart", "apple,t6050-dart", "apple,t8132-dart", + "apple,t8140-dart", "apple,t8142-dart", + }; + struct apple_dart_test_node t8132, other; + struct apple_dart dart = {}; + + /* The J773g dcpext0 and dispext0 DARTs' compatible list. */ + APPLE_DART_TEST_NODE(&t8132, "apple,t8132-dart\0apple,t8110-dart"); + dart.locked = true; + KUNIT_EXPECT_TRUE(test, apple_dart_keeps_fw_roots(&dart, &t8132.np)); + dart.fw_mirror = true; + KUNIT_EXPECT_TRUE(test, apple_dart_wants_fw_live_prot(&dart, &t8132.np)); + + /* Unlocked: the plain path, as on every other SoC. */ + dart.locked = false; + KUNIT_EXPECT_FALSE(test, apple_dart_keeps_fw_roots(&dart, &t8132.np)); + dart.fw_mirror = false; + KUNIT_EXPECT_FALSE(test, apple_dart_wants_fw_live_prot(&dart, &t8132.np)); + + /* A reserved-table handoff, or a DART borrowed on the 26.6.2 path. */ + dart.locked = true; + dart.fw_handoff = true; + KUNIT_EXPECT_FALSE(test, apple_dart_keeps_fw_roots(&dart, &t8132.np)); + dart.fw_handoff = false; + dart.preserve_display = true; + KUNIT_EXPECT_FALSE(test, apple_dart_keeps_fw_roots(&dart, &t8132.np)); + dart.preserve_display = false; + + /* The other SoCs: mirrored as before, without the protection change. */ + for (int i = 0; i < ARRAY_SIZE(mirrored); i++) { + apple_dart_test_node(&other, mirrored[i], strlen(mirrored[i]) + 1); + KUNIT_EXPECT_TRUE(test, apple_dart_keeps_fw_roots(&dart, &other.np)); + dart.fw_mirror = true; + KUNIT_EXPECT_EQ(test, apple_dart_wants_fw_live_prot(&dart, &other.np), + !strcmp(mirrored[i], "apple,t8132-dart")); + dart.fw_mirror = false; + } + /* SoCs without the retained-root path stay off it. */ + APPLE_DART_TEST_NODE(&other, "apple,t8122-dart\0apple,t8110-dart"); + KUNIT_EXPECT_FALSE(test, apple_dart_keeps_fw_roots(&dart, &other.np)); + APPLE_DART_TEST_NODE(&other, "apple,t8103-dart"); + KUNIT_EXPECT_FALSE(test, apple_dart_keeps_fw_roots(&dart, &other.np)); +} + static struct kunit_case apple_dart_test_cases[] = { KUNIT_CASE(apple_dart_test_strict_engines), KUNIT_CASE(apple_dart_test_topology), @@ -1456,6 +1527,7 @@ static struct kunit_case apple_dart_test_cases[] = { KUNIT_CASE(apple_dart_test_sync_unknown_roots), KUNIT_CASE(apple_dart_test_firmware_roots), KUNIT_CASE(apple_dart_test_fw_live_prot), + KUNIT_CASE(apple_dart_test_keeps_fw_roots), KUNIT_CASE(apple_dart_test_unmap_flush_after_publish_failure), KUNIT_CASE(apple_dart_test_gated_commands), KUNIT_CASE(apple_dart_test_resume_commands_failure), diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index bd0f8640ed6ff..510a9860ae353 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -5500,6 +5500,42 @@ static bool apple_dart_serves_t8132_dcp_v27(const struct device_node *dart_np) return serves; } +/* + * Whether a DART the boot loader left locked keeps its firmware's roots + * (fw_mirror): Linux tables go only into root slots the firmware left + * empty or must mirror its leaves exactly, so the firmware's own + * translations stay live. Every locked DART of these SoCs does unless the + * boot loader handed its reserved tables over (fw_handoff) or it is one of + * the T8132 display DARTs borrowed on the 26.6.2 path (preserve_display). + * T6050's boot loader leaves every display DART locked on four-level roots + * of its own (dart-dcpextN SID 23, dart-dispextN SIDs 0 and 16); a T8132 + * one locks the DARTs of the display processors it hands over on 27.2 (the + * J713's internal ones, the J773g's dcpext0). The DART's own state decides, + * not the board or the firmware build. + */ +static bool apple_dart_keeps_fw_roots(const struct apple_dart *dart, + const struct device_node *np) +{ + static const char *const compatible[] = { + "apple,t6041-dart", "apple,t6050-dart", "apple,t8132-dart", + "apple,t8140-dart", "apple,t8142-dart", NULL + }; + + return dart->locked && !dart->fw_handoff && !dart->preserve_display && + of_device_compatible_match(np, compatible); +} + +/* + * A T8132 fw_mirror DART's re-exported firmware segments take the protection + * of their live leaves (__apple_dart_fw_live_prot()). The other SoCs' locked + * DARTs keep what the core asks for: no row has checked the change there. + */ +static bool apple_dart_wants_fw_live_prot(const struct apple_dart *dart, + const struct device_node *np) +{ + return dart->fw_mirror && of_device_is_compatible(np, "apple,t8132-dart"); +} + static int apple_dart_probe(struct platform_device *pdev) { int ret, sid; @@ -6045,17 +6081,9 @@ static int apple_dart_probe(struct platform_device *pdev) /* Reserved table-page lifetime requires the matched three-level loader. */ dart->fw_handoff = apple_dart_fw_handoff_enabled(dart); dart->display_scanout = dart->fw_handoff && apple_dart_display_scanout(dev->of_node); - /* - * Preserve our retained-root path when no reserved-table handoff exists. - * T6050's boot loader leaves every display DART locked on four-level - * roots of its own (dart-dcpextN SID 23, dart-dispextN SIDs 0 and 16). - */ - dart->fw_mirror = dart->locked && !dart->fw_handoff && - (of_device_is_compatible(dev->of_node, "apple,t6041-dart") || - of_device_is_compatible(dev->of_node, "apple,t6050-dart") || - of_device_is_compatible(dev->of_node, "apple,t8140-dart") || - of_device_is_compatible(dev->of_node, "apple,t8142-dart") || - t8132_display_v27); + /* Preserve our retained-root path when no reserved-table handoff exists. */ + dart->fw_mirror = apple_dart_keeps_fw_roots(dart, dev->of_node); + dart->fw_live_prot = apple_dart_wants_fw_live_prot(dart, dev->of_node); /* * The firmware-27 backend runs on the locked roots alone: a DART that * is not locked, or whose boot loader also handed over reserved tables, @@ -6067,7 +6095,8 @@ static int apple_dart_probe(struct platform_device *pdev) dev_err(dev, "T8132 internal display DART on the 27.2 image: NOT locked: refusing\n"); else if (t8132_display_v27) dev_err(dev, "T8132 internal display DART on the 27.2 image: locked with a reserved-table handoff: refusing\n"); - dart->fw_live_prot = t8132_display_v27; + else if (dart->fw_live_prot) + dev_info(dev, "T8132 DART locked by the boot loader: locked roots kept (mirror)\n"); if (t8132_display_v27 && !dart->fw_mirror) { ret = -EINVAL; goto err_clk_disable;