[PATCH i-g-t v6 24/31] lib/intel_aux_pgtable: Adopt to handle canonized addresses

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Mon Oct 19 07:51:14 UTC 2020


With simple allocator we try to use high offsets from default
to exercise canonizing/decanonizing is working properly.
Alter pgtable to allow proper calculation on such offsets.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
 lib/intel_aux_pgtable.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/lib/intel_aux_pgtable.c b/lib/intel_aux_pgtable.c
index 7a1b9113..a970b708 100644
--- a/lib/intel_aux_pgtable.c
+++ b/lib/intel_aux_pgtable.c
@@ -68,7 +68,7 @@ static uint64_t last_buf_surface_end(struct intel_buf *buf)
 	int i;
 
 	for (i = 0; i < num_surfaces; i++) {
-		uint64_t surface_end = buf->surface[i].offset +
+		uint64_t surface_end = DECANONICAL(buf->surface[i].offset) +
 				       buf->surface[i].size;
 
 		if (surface_end > end_offset)
@@ -89,18 +89,20 @@ pgt_table_count(int address_bits, struct intel_buf **bufs, int buf_count)
 	end = 0;
 	for (i = 0; i < buf_count; i++) {
 		struct intel_buf *buf = bufs[i];
-		uint64_t start;
+		uint64_t start, offset;
+
+		offset = DECANONICAL(buf->addr.offset);
 
 		/* We require bufs to be sorted. */
 		igt_assert(i == 0 ||
-			   buf->addr.offset >= bufs[i - 1]->addr.offset +
-					       intel_buf_bo_size(bufs[i - 1]));
+			   offset >= DECANONICAL(bufs[i - 1]->addr.offset) +
+				intel_buf_bo_size(bufs[i - 1]));
+		start = ALIGN_DOWN(offset, 1UL << address_bits);
 
-		start = ALIGN_DOWN(buf->addr.offset, 1UL << address_bits);
 		/* Avoid double counting for overlapping aligned bufs. */
 		start = max(start, end);
 
-		end = ALIGN(buf->addr.offset + last_buf_surface_end(buf),
+		end = ALIGN(offset + last_buf_surface_end(buf),
 			    1UL << address_bits);
 		igt_assert(end >= start);
 
@@ -180,11 +182,11 @@ pgt_get_child_table(struct pgtable *pgt, uint64_t parent_table,
 		uint32_t offset;
 
 		child_table = pgt_alloc_table(pgt, level - 1);
-		igt_assert(!((child_table + pgt->buf->addr.offset) &
+		igt_assert(!((child_table + DECANONICAL(pgt->buf->addr.offset)) &
 			     ~ptr_mask(pgt, level)));
 
 		pte = child_table | flags;
-		*child_entry_ptr = pgt->buf->addr.offset + pte;
+		*child_entry_ptr = DECANONICAL(pgt->buf->addr.offset) + pte;
 
 		igt_assert(pte <= INT32_MAX);
 
@@ -197,7 +199,7 @@ pgt_get_child_table(struct pgtable *pgt, uint64_t parent_table,
 						pgt->buf->addr.offset);
 	} else {
 		child_table = (*child_entry_ptr & ptr_mask(pgt, level)) -
-			      pgt->buf->addr.offset;
+			      DECANONICAL(pgt->buf->addr.offset);
 	}
 
 	return child_table;
@@ -346,11 +348,11 @@ pgt_populate_entries_for_buf(struct pgtable *pgt,
 			     uint64_t top_table,
 			     int surface_idx)
 {
-	uint64_t surface_addr = buf->addr.offset +
+	uint64_t surface_addr = DECANONICAL(buf->addr.offset) +
 				buf->surface[surface_idx].offset;
 	uint64_t surface_end = surface_addr +
 			       buf->surface[surface_idx].size;
-	uint64_t aux_addr = buf->addr.offset + buf->ccs[surface_idx].offset;
+	uint64_t aux_addr = DECANONICAL(buf->addr.offset) + buf->ccs[surface_idx].offset;
 	uint64_t l1_flags = pgt_get_l1_flags(buf, surface_idx);
 	uint64_t lx_flags = pgt_get_lx_flags();
 
@@ -491,11 +493,15 @@ static void
 aux_pgtable_reserve_buf_slot(struct intel_buf **bufs, int buf_count,
 			     struct intel_buf *new_buf)
 {
+	uint64_t curr, newone;
 	int i;
 
-	for (i = 0; i < buf_count; i++)
-		if (bufs[i]->addr.offset > new_buf->addr.offset)
+	for (i = 0; i < buf_count; i++) {
+		curr = DECANONICAL(bufs[i]->addr.offset);
+		newone = DECANONICAL(new_buf->addr.offset);
+		if (curr > newone)
 			break;
+	}
 
 	memmove(&bufs[i + 1], &bufs[i], sizeof(bufs[0]) * (buf_count - i));
 
-- 
2.26.0



More information about the Intel-gfx-trybot mailing list