asahi/virtio: fix allocate-with-alignment

fixes crashes when spilling inside the microVM:

../src/asahi/lib/agx_scratch.c:176: void agx_scratch_realloc(struct agx_scratch *): Assertion `!(blocks_gpu & (block_size_bytes - 1))' failed

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31532>
This commit is contained in:
Alyssa Rosenzweig 2024-09-17 20:23:42 -04:00 committed by Marge Bot
parent e0cda48a90
commit 8f9cf43828
3 changed files with 6 additions and 11 deletions

View file

@ -203,8 +203,9 @@ agx_bo_create(struct agx_device *dev, unsigned size, unsigned align,
struct agx_bo *bo;
assert(size > 0);
/* To maximize BO cache usage, don't allocate tiny BOs */
size = ALIGN_POT(size, 16384);
/* BOs are allocated in pages */
size = ALIGN_POT(size, dev->params.vm_page_size);
align = MAX2(align, dev->params.vm_page_size);
/* See if we have a BO already in the cache */
bo = agx_bo_cache_fetch(dev, size, align, flags, true);

View file

@ -124,9 +124,6 @@ agx_bo_alloc(struct agx_device *dev, size_t size, size_t align,
struct agx_bo *bo;
unsigned handle = 0;
assert(size > 0);
size = ALIGN_POT(size, dev->params.vm_page_size);
/* executable implies low va */
assert(!(flags & AGX_BO_EXEC) || (flags & AGX_BO_LOW_VA));
@ -157,7 +154,7 @@ agx_bo_alloc(struct agx_device *dev, size_t size, size_t align,
assert(!memcmp(bo, &((struct agx_bo){}), sizeof(*bo)));
bo->size = gem_create.size;
bo->align = MAX2(dev->params.vm_page_size, align);
bo->align = align;
bo->flags = flags;
bo->handle = handle;
bo->prime_fd = -1;

View file

@ -60,8 +60,6 @@ agx_virtio_bo_alloc(struct agx_device *dev, size_t size, size_t align,
struct agx_bo *bo;
unsigned handle = 0;
size = ALIGN_POT(size, dev->params.vm_page_size);
/* executable implies low va */
assert(!(flags & AGX_BO_EXEC) || (flags & AGX_BO_LOW_VA));
@ -84,8 +82,7 @@ agx_virtio_bo_alloc(struct agx_device *dev, size_t size, size_t align,
uint32_t blob_id = p_atomic_inc_return(&dev->next_blob_id);
enum agx_va_flags va_flags = flags & AGX_BO_LOW_VA ? AGX_VA_USC : 0;
struct agx_va *va =
agx_va_alloc(dev, size, dev->params.vm_page_size, va_flags, 0);
struct agx_va *va = agx_va_alloc(dev, size, align, va_flags, 0);
if (!va) {
fprintf(stderr, "Failed to allocate BO VMA\n");
return NULL;
@ -110,7 +107,7 @@ agx_virtio_bo_alloc(struct agx_device *dev, size_t size, size_t align,
assert(!memcmp(bo, &((struct agx_bo){}), sizeof(*bo)));
bo->size = size;
bo->align = MAX2(dev->params.vm_page_size, align);
bo->align = align;
bo->flags = flags;
bo->handle = handle;
bo->prime_fd = -1;