panfrost: Don't segfault on unknown models

If we don't recognize the model, dev->model will be NULL. In that case, we can't
dereference dev->model to get the tilebuffer size. If we do, we'll segfault,
instead of gracefully refusing to probe and loading the swrast instead.

Fixes: 96d65b47c7 ("panfrost: Use implementation-specific tile size")
Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18115>
(cherry picked from commit 93f69e0452)
This commit is contained in:
Alyssa Rosenzweig
2022-08-17 15:20:28 -04:00
committed by Dylan Baker
parent 5c6b687e04
commit 8dd736aa04
2 changed files with 19 additions and 8 deletions

View File

@@ -85,7 +85,7 @@
"description": "panfrost: Don't segfault on unknown models",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "96d65b47c715155bb0403f3e0b5555b348d68539"
},

View File

@@ -284,11 +284,16 @@ panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev)
dev->memctx = memctx;
dev->gpu_id = panfrost_query_gpu_version(fd);
dev->arch = pan_arch(dev->gpu_id);
dev->core_count = panfrost_query_core_count(fd, &dev->core_id_range);
dev->thread_tls_alloc = panfrost_query_thread_tls_alloc(fd, dev->arch);
dev->kernel_version = drmGetVersion(fd);
dev->revision = panfrost_query_gpu_revision(fd);
dev->model = panfrost_get_model(dev->gpu_id);
/* If we don't recognize the model, bail early */
if (!dev->model)
return;
dev->core_count = panfrost_query_core_count(fd, &dev->core_id_range);
dev->thread_tls_alloc = panfrost_query_thread_tls_alloc(fd, dev->arch);
dev->optimal_tib_size = panfrost_query_optimal_tib_size(dev);
dev->compressed_formats = panfrost_query_compressed_formats(fd);
dev->tiler_features = panfrost_query_tiler_features(fd);
@@ -329,11 +334,17 @@ panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev)
void
panfrost_close_device(struct panfrost_device *dev)
{
pthread_mutex_destroy(&dev->submit_lock);
panfrost_bo_unreference(dev->tiler_heap);
panfrost_bo_cache_evict_all(dev);
pthread_mutex_destroy(&dev->bo_cache.lock);
/* If we don't recognize the model, the rest of the device won't exist,
* we will have early-exited the device open.
*/
if (dev->model) {
pthread_mutex_destroy(&dev->submit_lock);
panfrost_bo_unreference(dev->tiler_heap);
panfrost_bo_cache_evict_all(dev);
pthread_mutex_destroy(&dev->bo_cache.lock);
util_sparse_array_finish(&dev->bo_map);
}
drmFreeVersion(dev->kernel_version);
util_sparse_array_finish(&dev->bo_map);
close(dev->fd);
}