drm/nouveau/fence: fix a race where fence->channel can disappear
authorBen Skeggs <bskeggs@redhat.com>
Fri, 4 May 2012 06:25:47 +0000 (16:25 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Thu, 24 May 2012 06:55:58 +0000 (16:55 +1000)
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/nouveau_fence.c
drivers/gpu/drm/nouveau/nouveau_fence.h
drivers/gpu/drm/nouveau/nv04_fence.c
drivers/gpu/drm/nouveau/nv10_fence.c
drivers/gpu/drm/nouveau/nv84_fence.c
drivers/gpu/drm/nouveau/nvc0_fence.c

index 4ba41a45114fb1e7e64a6a617b8422e8d0f1d854..3c180493dab828c286b39531905f9697330f3c8b 100644 (file)
@@ -147,15 +147,19 @@ nouveau_fence_wait(struct nouveau_fence *fence, bool lazy, bool intr)
 int
 nouveau_fence_sync(struct nouveau_fence *fence, struct nouveau_channel *chan)
 {
-       struct nouveau_channel *prev = fence ? fence->channel : NULL;
        struct drm_device *dev = chan->dev;
        struct nouveau_fence_priv *priv = nv_engine(dev, NVOBJ_ENGINE_FENCE);
+       struct nouveau_channel *prev;
        int ret = 0;
 
-       if (unlikely(prev && prev != chan && !nouveau_fence_done(fence))) {
-               ret = priv->sync(fence, chan);
-               if (unlikely(ret))
-                       ret = nouveau_fence_wait(fence, true, false);
+       prev = fence ? nouveau_channel_get_unlocked(fence->channel) : NULL;
+       if (prev) {
+               if (unlikely(prev != chan && !nouveau_fence_done(fence))) {
+                       ret = priv->sync(fence, prev, chan);
+                       if (unlikely(ret))
+                               ret = nouveau_fence_wait(fence, true, false);
+               }
+               nouveau_channel_put_unlocked(&prev);
        }
 
        return ret;
index ec9afa775ea76f0ab472788aac5ac972d3c1f7cd..82ba733393ae03a19909268d30fc78f3b84cf9f3 100644 (file)
@@ -34,7 +34,8 @@ struct nouveau_fence_chan {
 struct nouveau_fence_priv {
        struct nouveau_exec_engine engine;
        int (*emit)(struct nouveau_fence *);
-       int (*sync)(struct nouveau_fence *, struct nouveau_channel *);
+       int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
+                   struct nouveau_channel *);
        u32 (*read)(struct nouveau_channel *);
 };
 
index 08bd2ceaefefb870ecfc6ef0e2300b9f7ecf0273..abe89db6de24e4e9736b92a92cae899884945133 100644 (file)
@@ -51,7 +51,8 @@ nv04_fence_emit(struct nouveau_fence *fence)
 }
 
 static int
-nv04_fence_sync(struct nouveau_fence *fence, struct nouveau_channel *chan)
+nv04_fence_sync(struct nouveau_fence *fence,
+               struct nouveau_channel *prev, struct nouveau_channel *chan)
 {
        return -ENODEV;
 }
index 10831eaff958b53281b59d18bac044693810cbfb..8a1b75009185dcc735af23265b8065e163ba19c1 100644 (file)
@@ -52,17 +52,19 @@ nv10_fence_emit(struct nouveau_fence *fence)
        return ret;
 }
 
+
 static int
-nv10_fence_sync(struct nouveau_fence *fence, struct nouveau_channel *chan)
+nv10_fence_sync(struct nouveau_fence *fence,
+               struct nouveau_channel *prev, struct nouveau_channel *chan)
 {
        return -ENODEV;
 }
 
 static int
-nv17_fence_sync(struct nouveau_fence *fence, struct nouveau_channel *chan)
+nv17_fence_sync(struct nouveau_fence *fence,
+               struct nouveau_channel *prev, struct nouveau_channel *chan)
 {
        struct nv10_fence_priv *priv = nv_engine(chan->dev, NVOBJ_ENGINE_FENCE);
-       struct nouveau_channel *prev = fence->channel;
        u32 value;
        int ret;
 
index d23dbc06f4363e592cf1faca93469e2584ab2c36..0ac98c0efc71967a18f507c1036b4a535bfd449d 100644 (file)
@@ -55,16 +55,18 @@ nv84_fence_emit(struct nouveau_fence *fence)
        return ret;
 }
 
+
 static int
-nv84_fence_sync(struct nouveau_fence *fence, struct nouveau_channel *chan)
+nv84_fence_sync(struct nouveau_fence *fence,
+               struct nouveau_channel *prev, struct nouveau_channel *chan)
 {
        int ret = RING_SPACE(chan, 7);
        if (ret == 0) {
                BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
                OUT_RING  (chan, NvSema);
                BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
-               OUT_RING  (chan, upper_32_bits(fence->channel->id * 16));
-               OUT_RING  (chan, lower_32_bits(fence->channel->id * 16));
+               OUT_RING  (chan, upper_32_bits(prev->id * 16));
+               OUT_RING  (chan, lower_32_bits(prev->id * 16));
                OUT_RING  (chan, fence->sequence);
                OUT_RING  (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_GEQUAL);
                FIRE_RING (chan);
index 41545f15c4d0f67a4e319fec400f543f690451a7..817228cd1a950a7940b4aa715f92f3858b60ad8b 100644 (file)
@@ -60,10 +60,11 @@ nvc0_fence_emit(struct nouveau_fence *fence)
 }
 
 static int
-nvc0_fence_sync(struct nouveau_fence *fence, struct nouveau_channel *chan)
+nvc0_fence_sync(struct nouveau_fence *fence,
+               struct nouveau_channel *prev, struct nouveau_channel *chan)
 {
        struct nvc0_fence_chan *fctx = chan->engctx[NVOBJ_ENGINE_FENCE];
-       u64 addr = fctx->vma.offset + fence->channel->id * 16;
+       u64 addr = fctx->vma.offset + prev->id * 16;
        int ret;
 
        ret = RING_SPACE(chan, 5);