From 46d51a741dcf626d60b89398f05d5cc6201b6a82 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sat, 28 Nov 2026 18:07:39 +0100 Subject: [PATCH] drm/apple: dcp: allow 4 KiB alignment for firmware-placed live RTKit buffers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In dcp_rtkit_live_parse(), every apple,rtkit-buffers entry was checked with PAGE_ALIGNED(iova) && PAGE_ALIGNED(size). On 16 KiB arm64 kernels, this rejects firmware-placed (is_mapped == 1) buffers whose RTKit addresses use 4 KiB granularity inside a pre-mapped firmware carveout — for example T8103 (M1 Mac mini J274, fw 27.2.1) places the crashlog buffer (ep 1) at iova 0x276000 (size 0x10000) inside dcp_data (0xbe6510000+0x300000), causing dcp_rtkit_live_parse() to return -EINVAL and aborting apple-drm probe when adopting a live HDMI session from aura. Both dcp_check_iova_contiguous() and dcp_vmap_wc() already handle sub-page offsets cleanly (offset_in_page(phys) + multi-page vmap). Split the validation into dcp_rtkit_live_buf_valid(): - Firmware-placed buffers (is_mapped == 1): require 4 KiB alignment (IS_ALIGNED(..., SZ_4K)), matching the RTKit buffer request protocol. - Loader-allocated buffers (is_mapped == 0): keep host PAGE_ALIGNED() so their no-map reserved-memory carveouts never alias neighbouring pages. Add a KUnit test case (dcp_handoff_live_rtkit_buf_valid) in dcp_handoff_test.c covering firmware-placed 4 KiB buffers, loader-allocated page alignment, endpoint IDs, flags, size limits, and address wraparound. Tested: - J274 (M1 Mac mini, T8103, macOS 27.2.1 main OS, 16 KiB kernel) booted with HDMI (1920x1200@60) via aurora-silicon/aura#564 live handoff (dcp-live-v1, ep1 iova=0x276000 size=0x10000 is_mapped=1, ep2/ep4 loader-allocated): 231c00000.dcp adopted the live RTKit session cleanly ("DCP booted", "set_digital_out_mode finished:8242", "boot scanout retired by displayed swap 3", fb0 appledrmfb, 0 DART faults, 0 failed units), 271c00000.dcp and USB-C Type-C muxes bound cleanly. - KUnit (arm64): apple-dcp-handoff 3/3 passed (dcp_handoff_external_idle, dcp_handoff_boot_notch, dcp_handoff_live_rtkit_buf_valid). - scripts/checkpatch.pl: 0 errors, 0 warnings. Risk: low — only relaxes alignment from PAGE_SIZE to SZ_4K for firmware-placed (is_mapped == 1) live RTKit buffers, which are still verified to be contiguously DART-mapped inside a no-map DCP carveout and mapped via dcp_vmap_wc(). Loader-allocated buffers keep full PAGE_ALIGNED() enforcement. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/dcp.c | 22 +++++++++++++++++--- drivers/gpu/drm/apple/dcp_handoff_test.c | 26 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index ba73ba857249a..d8c99eccc0973 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -2092,6 +2092,24 @@ static void dcp_rtkit_live_unmap(struct dcp_rtkit_live *live) live->session.num_buffers = 0; } +/* + * Validate one apple,rtkit-buffers tuple before translating it through the DART. + * Firmware-placed buffers (is_mapped == 1) use RTKit's 4 KiB granularity inside + * a pre-mapped firmware carveout (for example T8103's crashlog at 0x276000 on a + * 16 KiB host kernel); loader-allocated buffers (is_mapped == 0) sit in no-map + * reserved-memory regions and must be host page-aligned. + */ +static bool dcp_rtkit_live_buf_valid(u32 ep, u64 iova, u64 size, u32 is_mapped) +{ + if ((ep != 1 && ep != 2 && ep != 4 && ep != 8) || is_mapped > 1) + return false; + if (!size || size > SZ_16M || iova + size < iova) + return false; + if (is_mapped) + return IS_ALIGNED(iova, SZ_4K) && IS_ALIGNED(size, SZ_4K); + return PAGE_ALIGNED(iova) && PAGE_ALIGNED(size); +} + /* * A boot stage that negotiated RTKit with this DCP and handed it over running * describes the session on the node, with the RTKit handoff properties of other @@ -2167,9 +2185,7 @@ static int dcp_rtkit_live_parse(struct apple_dcp *dcp, struct dcp_rtkit_live *li phys_addr_t phys; /* The system endpoints with shared buffers, as for other handoffs. */ - if ((t[0] != 1 && t[0] != 2 && t[0] != 4 && t[0] != 8) || - t[4] > 1 || !size || size > SZ_16M || !PAGE_ALIGNED(iova) || - !PAGE_ALIGNED(size) || iova + size < iova) { + if (!dcp_rtkit_live_buf_valid(t[0], iova, size, t[4])) { ret = -EINVAL; goto fail; } diff --git a/drivers/gpu/drm/apple/dcp_handoff_test.c b/drivers/gpu/drm/apple/dcp_handoff_test.c index 22c88773b9114..533e7add8ca58 100644 --- a/drivers/gpu/drm/apple/dcp_handoff_test.c +++ b/drivers/gpu/drm/apple/dcp_handoff_test.c @@ -109,9 +109,35 @@ static void dcp_handoff_boot_notch(struct kunit *test) KUNIT_EXPECT_FALSE(test, dcp_handoff_notch(unterminated, sizeof(unterminated))); } +static void dcp_handoff_live_rtkit_buf_valid(struct kunit *test) +{ + /* Firmware-placed (is_mapped == 1) uses RTKit's 4 KiB granularity. */ + KUNIT_EXPECT_TRUE(test, dcp_rtkit_live_buf_valid(1, 0x276000, SZ_64K, 1)); + KUNIT_EXPECT_TRUE(test, dcp_rtkit_live_buf_valid(8, 0x277000, SZ_4K, 1)); + KUNIT_EXPECT_FALSE(test, dcp_rtkit_live_buf_valid(1, 0x276800, SZ_64K, 1)); + KUNIT_EXPECT_FALSE(test, dcp_rtkit_live_buf_valid(1, 0x276000, 0x800, 1)); + + /* Loader-allocated (is_mapped == 0) must be host page-aligned. */ + KUNIT_EXPECT_TRUE(test, dcp_rtkit_live_buf_valid(2, 0xf10004000ULL, PAGE_SIZE, 0)); + KUNIT_EXPECT_TRUE(test, dcp_rtkit_live_buf_valid(4, 0xf10000000ULL, PAGE_SIZE, 0)); + if (PAGE_SIZE > SZ_4K) { + KUNIT_EXPECT_FALSE(test, dcp_rtkit_live_buf_valid(2, 0xf10001000ULL, PAGE_SIZE, 0)); + KUNIT_EXPECT_FALSE(test, dcp_rtkit_live_buf_valid(2, 0xf10004000ULL, SZ_4K, 0)); + } + + /* Endpoint, flag, size and wraparound bounds. */ + KUNIT_EXPECT_FALSE(test, dcp_rtkit_live_buf_valid(0, 0x276000, SZ_64K, 1)); + KUNIT_EXPECT_FALSE(test, dcp_rtkit_live_buf_valid(3, 0x276000, SZ_64K, 1)); + KUNIT_EXPECT_FALSE(test, dcp_rtkit_live_buf_valid(1, 0x276000, SZ_64K, 2)); + KUNIT_EXPECT_FALSE(test, dcp_rtkit_live_buf_valid(1, 0x276000, 0, 1)); + KUNIT_EXPECT_FALSE(test, dcp_rtkit_live_buf_valid(1, 0x276000, SZ_16M + SZ_4K, 1)); + KUNIT_EXPECT_FALSE(test, dcp_rtkit_live_buf_valid(1, U64_MAX - SZ_4K + 1, SZ_4K, 1)); +} + static struct kunit_case dcp_handoff_cases[] = { KUNIT_CASE(dcp_handoff_external_idle), KUNIT_CASE(dcp_handoff_boot_notch), + KUNIT_CASE(dcp_handoff_live_rtkit_buf_valid), {} };