Skip to content

Commit 14eb0cb

Browse files
committed
drm/msm/a6xx: Track current ctx by seqno
In theory a context can be destroyed and a new one allocated at the same address, making the pointer comparision to detect when we don't need to update the current pagetables invalid. Instead assign a sequence number to each context on creation, and use this for the check. Fixes: 84c31ee ("drm/msm/a6xx: Add support for per-instance pagetables") Signed-off-by: Rob Clark <robdclark@chromium.org>
1 parent f6f5907 commit 14eb0cb

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

drivers/gpu/drm/msm/adreno/a6xx_gpu.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static void a6xx_set_pagetable(struct a6xx_gpu *a6xx_gpu,
106106
u32 asid;
107107
u64 memptr = rbmemptr(ring, ttbr0);
108108

109-
if (ctx == a6xx_gpu->cur_ctx)
109+
if (ctx->seqno == a6xx_gpu->cur_ctx_seqno)
110110
return;
111111

112112
if (msm_iommu_pagetable_params(ctx->aspace->mmu, &ttbr, &asid))
@@ -139,7 +139,7 @@ static void a6xx_set_pagetable(struct a6xx_gpu *a6xx_gpu,
139139
OUT_PKT7(ring, CP_EVENT_WRITE, 1);
140140
OUT_RING(ring, 0x31);
141141

142-
a6xx_gpu->cur_ctx = ctx;
142+
a6xx_gpu->cur_ctx_seqno = ctx->seqno;
143143
}
144144

145145
static void a6xx_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit)
@@ -1081,7 +1081,7 @@ static int hw_init(struct msm_gpu *gpu)
10811081
/* Always come up on rb 0 */
10821082
a6xx_gpu->cur_ring = gpu->rb[0];
10831083

1084-
a6xx_gpu->cur_ctx = NULL;
1084+
a6xx_gpu->cur_ctx_seqno = 0;
10851085

10861086
/* Enable the SQE_to start the CP engine */
10871087
gpu_write(gpu, REG_A6XX_CP_SQE_CNTL, 1);

drivers/gpu/drm/msm/adreno/a6xx_gpu.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@ struct a6xx_gpu {
1919
uint64_t sqe_iova;
2020

2121
struct msm_ringbuffer *cur_ring;
22-
struct msm_file_private *cur_ctx;
22+
23+
/**
24+
* cur_ctx_seqno:
25+
*
26+
* The ctx->seqno value of the context with current pgtables
27+
* installed. Tracked by seqno rather than pointer value to
28+
* avoid dangling pointers, and cases where a ctx can be freed
29+
* and a new one created with the same address.
30+
*/
31+
int cur_ctx_seqno;
2332

2433
struct a6xx_gmu gmu;
2534

drivers/gpu/drm/msm/msm_drv.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ static void load_gpu(struct drm_device *dev)
682682

683683
static int context_init(struct drm_device *dev, struct drm_file *file)
684684
{
685+
static atomic_t ident = ATOMIC_INIT(0);
685686
struct msm_drm_private *priv = dev->dev_private;
686687
struct msm_file_private *ctx;
687688

@@ -698,6 +699,8 @@ static int context_init(struct drm_device *dev, struct drm_file *file)
698699
ctx->aspace = msm_gpu_create_private_address_space(priv->gpu, current);
699700
file->driver_priv = ctx;
700701

702+
ctx->seqno = atomic_inc_return(&ident);
703+
701704
return 0;
702705
}
703706

drivers/gpu/drm/msm/msm_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct msm_file_private {
5959
int queueid;
6060
struct msm_gem_address_space *aspace;
6161
struct kref ref;
62+
int seqno;
6263
};
6364

6465
enum msm_mdp_plane_property {

0 commit comments

Comments
 (0)