lima,panfrost: Do not ralloc contexts against the screen

ralloc is not thread-safe. While a given context can only be accessed from a
single thread at once, multiple contexts can be created against the same screen
at once. The ralloc allocations against the shared screens will race. Depending
on the result of the race, the same block of memory can be returned as the two
new contexts in two different threads, causing a use-after-free when the context
is freed later.

We free the context explicitly when it's destroyed anyway. If screens are
getting destroyed without the contexts getting destroyed first, that's a state
tracker bug, not a Panfrost one.

This matches what Iris does.

Fixes crash in test_integer_ops.int_math on Panfrost.

Fixes: 0fcf73bc2d ("panfrost: Move to use ralloc for some allocations")
Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17234>
This commit is contained in:
Alyssa Rosenzweig
2022-06-24 10:42:00 -04:00
committed by Marge Bot
parent a530b90cd3
commit f18492faa9
2 changed files with 2 additions and 2 deletions

View File

@@ -205,7 +205,7 @@ lima_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
struct lima_screen *screen = lima_screen(pscreen);
struct lima_context *ctx;
ctx = rzalloc(screen, struct lima_context);
ctx = rzalloc(NULL, struct lima_context);
if (!ctx)
return NULL;

View File

@@ -1060,7 +1060,7 @@ panfrost_set_stream_output_targets(struct pipe_context *pctx,
struct pipe_context *
panfrost_create_context(struct pipe_screen *screen, void *priv, unsigned flags)
{
struct panfrost_context *ctx = rzalloc(screen, struct panfrost_context);
struct panfrost_context *ctx = rzalloc(NULL, struct panfrost_context);
struct pipe_context *gallium = (struct pipe_context *) ctx;
struct panfrost_device *dev = pan_device(screen);