From 6ffe16a5c441e15b7e81c99666c6f05da687342b Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Tue, 30 Jul 2024 13:18:43 -0700 Subject: [PATCH] freedreno/drm/virtio: Fix issues with 16k (or larger) page sizes Signed-off-by: Rob Clark Fixes: e6b2785811c2 ("freedreno/drm/virtio: Use userspace IOVA allocation") Part-of: (cherry picked from commit 87c889cd8af09aa6e05b55f66c8460ae293a3512) --- .pick_status.json | 2 +- src/freedreno/drm/freedreno_bo_cache.c | 10 +++++----- src/freedreno/drm/freedreno_device.c | 4 ++++ src/freedreno/drm/freedreno_priv.h | 1 + src/freedreno/drm/freedreno_ringbuffer_sp.c | 2 +- src/freedreno/drm/msm/msm_device.c | 2 +- src/freedreno/drm/virtio/virtio_priv.h | 2 +- 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index e294fe5c1ea..a7b55ca91d0 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -7154,7 +7154,7 @@ "description": "freedreno/drm/virtio: Fix issues with 16k (or larger) page sizes", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "e6b2785811c23e44d3acfeef71ef240d95fc1663", "notes": null diff --git a/src/freedreno/drm/freedreno_bo_cache.c b/src/freedreno/drm/freedreno_bo_cache.c index 9d3c2123054..933e246fe08 100644 --- a/src/freedreno/drm/freedreno_bo_cache.c +++ b/src/freedreno/drm/freedreno_bo_cache.c @@ -123,13 +123,13 @@ fd_bo_cache_init(struct fd_bo_cache *cache, int coarse, const char *name) * width/height alignment and rounding of sizes to pages will * get us useful cache hit rates anyway) */ - add_bucket(cache, 4096); - add_bucket(cache, 4096 * 2); + add_bucket(cache, os_page_size); + add_bucket(cache, os_page_size * 2); if (!coarse) - add_bucket(cache, 4096 * 3); + add_bucket(cache, os_page_size * 3); /* Initialize the linked lists for BO reuse cache. */ - for (size = 4 * 4096; size <= cache_max_size; size *= 2) { + for (size = 4 * os_page_size; size <= cache_max_size; size *= 2) { add_bucket(cache, size); if (!coarse) { add_bucket(cache, size + size * 1 / 4); @@ -241,7 +241,7 @@ fd_bo_cache_alloc(struct fd_bo_cache *cache, uint32_t *size, uint32_t flags) struct fd_bo *bo = NULL; struct fd_bo_bucket *bucket; - *size = align(*size, 4096); + *size = align(*size, os_page_size); bucket = get_bucket(cache, *size); struct list_head freelist; diff --git a/src/freedreno/drm/freedreno_device.c b/src/freedreno/drm/freedreno_device.c index 7c00b8610a0..0895a1e52e7 100644 --- a/src/freedreno/drm/freedreno_device.c +++ b/src/freedreno/drm/freedreno_device.c @@ -39,6 +39,8 @@ struct fd_device *msm_device_new(int fd, drmVersionPtr version); struct fd_device *virtio_device_new(int fd, drmVersionPtr version); #endif +uint64_t os_page_size = 4096; + struct fd_device * fd_device_new(int fd) { @@ -46,6 +48,8 @@ fd_device_new(int fd) drmVersionPtr version; bool use_heap = false; + os_get_page_size(&os_page_size); + /* figure out if we are kgsl or msm drm driver: */ version = drmGetVersion(fd); if (!version) { diff --git a/src/freedreno/drm/freedreno_priv.h b/src/freedreno/drm/freedreno_priv.h index b59629a7ee5..fc2954d89fa 100644 --- a/src/freedreno/drm/freedreno_priv.h +++ b/src/freedreno/drm/freedreno_priv.h @@ -56,6 +56,7 @@ extern simple_mtx_t table_lock; extern simple_mtx_t fence_lock; +extern uint64_t os_page_size; #define SUBALLOC_SIZE (32 * 1024) /* Maximum known alignment requirement is a6xx's TEX_CONST at 16 dwords */ diff --git a/src/freedreno/drm/freedreno_ringbuffer_sp.c b/src/freedreno/drm/freedreno_ringbuffer_sp.c index 86e1cbe5693..ccd668171ec 100644 --- a/src/freedreno/drm/freedreno_ringbuffer_sp.c +++ b/src/freedreno/drm/freedreno_ringbuffer_sp.c @@ -782,7 +782,7 @@ fd_ringbuffer_sp_new_object(struct fd_pipe *pipe, uint32_t size) if (dev->suballoc_bo) fd_bo_del(dev->suballoc_bo); dev->suballoc_bo = - fd_bo_new_ring(dev, MAX2(SUBALLOC_SIZE, align(size, 4096))); + fd_bo_new_ring(dev, MAX2(SUBALLOC_SIZE, align(size, os_page_size))); fd_ring->offset = 0; } diff --git a/src/freedreno/drm/msm/msm_device.c b/src/freedreno/drm/msm/msm_device.c index 47ebf223cae..072d68c1c14 100644 --- a/src/freedreno/drm/msm/msm_device.c +++ b/src/freedreno/drm/msm/msm_device.c @@ -65,7 +65,7 @@ msm_device_new(int fd, drmVersionPtr version) if (version->version_minor >= FD_VERSION_CACHED_COHERENT) { struct drm_msm_gem_new new_req = { - .size = 0x1000, + .size = os_page_size, .flags = MSM_BO_CACHED_COHERENT, }; diff --git a/src/freedreno/drm/virtio/virtio_priv.h b/src/freedreno/drm/virtio/virtio_priv.h index 4b95ad85006..bf00ff4560d 100644 --- a/src/freedreno/drm/virtio/virtio_priv.h +++ b/src/freedreno/drm/virtio/virtio_priv.h @@ -94,7 +94,7 @@ virtio_dev_alloc_iova(struct fd_device *dev, uint32_t size) uint64_t iova; simple_mtx_lock(&virtio_dev->address_space_lock); - iova = util_vma_heap_alloc(&virtio_dev->address_space, size, 0x1000); + iova = util_vma_heap_alloc(&virtio_dev->address_space, size, os_page_size); simple_mtx_unlock(&virtio_dev->address_space_lock); return iova;