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
16 changes: 13 additions & 3 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2104,16 +2104,24 @@ 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)
{
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);
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);
}

/*
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions drivers/gpu/drm/apple/dcp_handoff_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading