diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index e90ac4e251c8e..6125397ee74eb 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -2104,6 +2104,12 @@ static void dcp_rtkit_live_unmap(struct dcp_rtkit_live *live) * 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. + * + * Crashlog, syslog and IOReport buffers are requested in 4 KiB pages. OSLog (8) + * states its size in bytes and only its address in pages, as RTKit takes it + * over (apple_rtkit_inherit_buffers()): a firmware that placed its own OSLog + * buffer may give a size that is not a whole page (T6050's external DCPs, + * 0x5ff8 bytes). */ static bool dcp_rtkit_live_buf_valid(u32 ep, u64 iova, u64 size, u32 is_mapped) { @@ -2111,9 +2117,11 @@ static bool dcp_rtkit_live_buf_valid(u32 ep, u64 iova, u64 size, u32 is_mapped) 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); + if (!is_mapped) + return PAGE_ALIGNED(iova) && PAGE_ALIGNED(size); + if (ep == 8) + return IS_ALIGNED(iova, SZ_4K); + return IS_ALIGNED(iova, SZ_4K) && IS_ALIGNED(size, SZ_4K); } /* @@ -2192,6 +2200,8 @@ static int dcp_rtkit_live_parse(struct apple_dcp *dcp, struct dcp_rtkit_live *li /* The system endpoints with shared buffers, as for other handoffs. */ if (!dcp_rtkit_live_buf_valid(t[0], iova, size, t[4])) { + dev_err(dcp->dev, "live RTKit buffer ep%u iova %#llx+%#llx (firmware-placed %u) is not valid\n", + 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 533e7add8ca58..72aecbc55e696 100644 --- a/drivers/gpu/drm/apple/dcp_handoff_test.c +++ b/drivers/gpu/drm/apple/dcp_handoff_test.c @@ -117,6 +117,12 @@ static void dcp_handoff_live_rtkit_buf_valid(struct kunit *test) 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)); + /* A firmware-placed OSLog buffer gives its size in bytes (T6050 dcpext). */ + KUNIT_EXPECT_TRUE(test, dcp_rtkit_live_buf_valid(8, 0x100039b4000ULL, 0x5ff8, 1)); + KUNIT_EXPECT_FALSE(test, dcp_rtkit_live_buf_valid(8, 0x100039b4800ULL, 0x5ff8, 1)); + KUNIT_EXPECT_FALSE(test, dcp_rtkit_live_buf_valid(2, 0x100039b4000ULL, 0x5ff8, 1)); + KUNIT_EXPECT_FALSE(test, dcp_rtkit_live_buf_valid(8, 0x100039b4000ULL, 0x5ff8, 0)); + /* 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));