From b5bcb658b4dcac0a08031b30a66c6780ea66c6ff Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 28 Sep 2023 01:22:21 -0700 Subject: [PATCH] iris: Ensure virtual addresses are aligned to 2MB for 2MB+ blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When allocating 2MB chunks of memory, the kernel can use 64K pages if both the virtual and physical addresses are aligned to 2MB. While we can't control the physical allocation, we can ensure the virtual address we use with softpin meets the requirements. Reviewed-by: José Roberto de Souza Part-of: --- src/gallium/drivers/iris/iris_bufmgr.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c index cee92c883fa..8c8698f979a 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.c +++ b/src/gallium/drivers/iris/iris_bufmgr.c @@ -371,10 +371,18 @@ vma_alloc(struct iris_bufmgr *bufmgr, { simple_mtx_assert_locked(&bufmgr->lock); + const unsigned _2mb = 2 * 1024 * 1024; + /* Force minimum alignment based on device requirements */ assert((alignment & (alignment - 1)) == 0); alignment = MAX2(alignment, bufmgr->devinfo.mem_alignment); + /* If the allocation is a multiple of 2MB, ensure the virtual address is + * aligned to 2MB, so that it's possible for the kernel to use 64K pages. + */ + if (size % _2mb == 0) + alignment = MAX2(alignment, _2mb); + if (memzone == IRIS_MEMZONE_BORDER_COLOR_POOL) return IRIS_BORDER_COLOR_POOL_ADDRESS;