Skip to content

Commit 2d5cff2

Browse files
Yogayaojialucasdemarchi
authored andcommitted
drm/xe: Fix out-of-bounds field write in MI_STORE_DATA_IMM
According to Bspec, bits 0~9 of MI_STORE_DATA_IMM must not exceed 0x3FE. The macro MI_SDI_NUM_QW(x) evaluates to 2 * x + 1, which means the condition 2 * x + 1 <= 0x3FE must be satisfied. Therefore, the maximum valid value for x is 0x1FE, not 0x1FF. v2 - Replace 0x1fe with macro MAX_PTE_PER_SDI (Auld, Matthew & Patelczyk, Maciej) v3 - Change macro MAX_PTE_PER_SDI from 0x1fe to 0x1feU (De Marchi, Lucas) Bspec: 60246 Fixes: 9c44fd5 ("drm/xe: Add migrate layer functions for SVM support") Cc: Matthew Brost <[email protected]> Cc: Brian3 Nguyen <[email protected]> Cc: Alex Zuo <[email protected]> Cc: Matthew Auld <[email protected]> Cc: Maciej Patelczyk <[email protected]> Cc: Lucas De Marchi <[email protected]> Suggested-by: Shuicheng Lin <[email protected]> Signed-off-by: Jia Yao <[email protected]> Reviewed-by: Matthew Brost <[email protected]> Reviewed-by: Lucas De Marchi <[email protected]> Reviewed-by: Maciej Patelczyk <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lucas De Marchi <[email protected]> (cherry picked from commit c038bdb) Signed-off-by: Lucas De Marchi <[email protected]>
1 parent d0b3b7b commit 2d5cff2

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

drivers/gpu/drm/xe/xe_migrate.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct xe_migrate {
8282
* of the instruction. Subtracting the instruction header (1 dword) and
8383
* address (2 dwords), that leaves 0x3FD dwords (0x1FE qwords) for PTE values.
8484
*/
85-
#define MAX_PTE_PER_SDI 0x1FE
85+
#define MAX_PTE_PER_SDI 0x1FEU
8686

8787
/**
8888
* xe_tile_migrate_exec_queue() - Get this tile's migrate exec queue.
@@ -1553,15 +1553,17 @@ static u32 pte_update_cmd_size(u64 size)
15531553
u64 entries = DIV_U64_ROUND_UP(size, XE_PAGE_SIZE);
15541554

15551555
XE_WARN_ON(size > MAX_PREEMPTDISABLE_TRANSFER);
1556+
15561557
/*
15571558
* MI_STORE_DATA_IMM command is used to update page table. Each
1558-
* instruction can update maximumly 0x1ff pte entries. To update
1559-
* n (n <= 0x1ff) pte entries, we need:
1560-
* 1 dword for the MI_STORE_DATA_IMM command header (opcode etc)
1561-
* 2 dword for the page table's physical location
1562-
* 2*n dword for value of pte to fill (each pte entry is 2 dwords)
1559+
* instruction can update maximumly MAX_PTE_PER_SDI pte entries. To
1560+
* update n (n <= MAX_PTE_PER_SDI) pte entries, we need:
1561+
*
1562+
* - 1 dword for the MI_STORE_DATA_IMM command header (opcode etc)
1563+
* - 2 dword for the page table's physical location
1564+
* - 2*n dword for value of pte to fill (each pte entry is 2 dwords)
15631565
*/
1564-
num_dword = (1 + 2) * DIV_U64_ROUND_UP(entries, 0x1ff);
1566+
num_dword = (1 + 2) * DIV_U64_ROUND_UP(entries, MAX_PTE_PER_SDI);
15651567
num_dword += entries * 2;
15661568

15671569
return num_dword;
@@ -1577,7 +1579,7 @@ static void build_pt_update_batch_sram(struct xe_migrate *m,
15771579

15781580
ptes = DIV_ROUND_UP(size, XE_PAGE_SIZE);
15791581
while (ptes) {
1580-
u32 chunk = min(0x1ffU, ptes);
1582+
u32 chunk = min(MAX_PTE_PER_SDI, ptes);
15811583

15821584
bb->cs[bb->len++] = MI_STORE_DATA_IMM | MI_SDI_NUM_QW(chunk);
15831585
bb->cs[bb->len++] = pt_offset;

0 commit comments

Comments
 (0)