Skip to content

Commit 705a412

Browse files
mwajdeczlucasdemarchi
authored andcommitted
drm/xe/pf: Clear all LMTT pages on alloc
Our LMEM buffer objects are not cleared by default on alloc and during VF provisioning we only setup LMTT PTEs for the actually provisioned LMEM range. But beyond that valid range we might leave some stale data that could either point to some other VFs allocations or even to the PF pages. Explicitly clear all new LMTT page to avoid the risk that a malicious VF would try to exploit that gap. While around add asserts to catch any undesired PTE overwrites and low-level debug traces to track LMTT PT life-cycle. Fixes: b1d2040 ("drm/xe/pf: Introduce Local Memory Translation Table") Signed-off-by: Michal Wajdeczko <[email protected]> Cc: Michał Winiarski <[email protected]> Cc: Lukasz Laguna <[email protected]> Reviewed-by: Michał Winiarski <[email protected]> Reviewed-by: Piotr Piórkowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] (cherry picked from commit 3fae691) Signed-off-by: Lucas De Marchi <[email protected]>
1 parent d7b8f8e commit 705a412

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/gpu/drm/xe/xe_lmtt.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ static struct xe_lmtt_pt *lmtt_pt_alloc(struct xe_lmtt *lmtt, unsigned int level
7878
}
7979

8080
lmtt_assert(lmtt, xe_bo_is_vram(bo));
81+
lmtt_debug(lmtt, "level=%u addr=%#llx\n", level, (u64)xe_bo_main_addr(bo, XE_PAGE_SIZE));
82+
83+
xe_map_memset(lmtt_to_xe(lmtt), &bo->vmap, 0, 0, bo->size);
8184

8285
pt->level = level;
8386
pt->bo = bo;
@@ -91,6 +94,9 @@ static struct xe_lmtt_pt *lmtt_pt_alloc(struct xe_lmtt *lmtt, unsigned int level
9194

9295
static void lmtt_pt_free(struct xe_lmtt_pt *pt)
9396
{
97+
lmtt_debug(&pt->bo->tile->sriov.pf.lmtt, "level=%u addr=%llx\n",
98+
pt->level, (u64)xe_bo_main_addr(pt->bo, XE_PAGE_SIZE));
99+
94100
xe_bo_unpin_map_no_vm(pt->bo);
95101
kfree(pt);
96102
}
@@ -226,9 +232,14 @@ static void lmtt_write_pte(struct xe_lmtt *lmtt, struct xe_lmtt_pt *pt,
226232

227233
switch (lmtt->ops->lmtt_pte_size(level)) {
228234
case sizeof(u32):
235+
lmtt_assert(lmtt, !overflows_type(pte, u32));
236+
lmtt_assert(lmtt, !pte || !iosys_map_rd(&pt->bo->vmap, idx * sizeof(u32), u32));
237+
229238
xe_map_wr(lmtt_to_xe(lmtt), &pt->bo->vmap, idx * sizeof(u32), u32, pte);
230239
break;
231240
case sizeof(u64):
241+
lmtt_assert(lmtt, !pte || !iosys_map_rd(&pt->bo->vmap, idx * sizeof(u64), u64));
242+
232243
xe_map_wr(lmtt_to_xe(lmtt), &pt->bo->vmap, idx * sizeof(u64), u64, pte);
233244
break;
234245
default:

0 commit comments

Comments
 (0)