drm/nouveau/falcon: protect against concurrent DMEM accesses
authorAlexandre Courbot <acourbot@nvidia.com>
Thu, 19 Jan 2017 03:11:15 +0000 (12:11 +0900)
committerBen Skeggs <bskeggs@redhat.com>
Tue, 7 Mar 2017 07:05:11 +0000 (17:05 +1000)
The falcon library may be used concurrently, especially after the
introduction of the msgqueue interface. Make it safe to use it that way.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/include/nvkm/engine/falcon.h
drivers/gpu/drm/nouveau/nvkm/falcon/base.c

index 7e498e65b1e8db8d9b965ed26327d33f6bd2b050..9384dff814942ebda6661479f975b087ad48a18b 100644 (file)
@@ -19,6 +19,7 @@ struct nvkm_falcon {
        u32 addr;
 
        struct mutex mutex;
+       struct mutex dmem_mutex;
        const struct nvkm_subdev *user;
 
        u8 version;
index 4852f313762f14ea97d8adc829c5b4c6a6472cff..ee25fdc21e1f697430b7b03da42ae1e70759aa72 100644 (file)
@@ -41,14 +41,22 @@ void
 nvkm_falcon_load_dmem(struct nvkm_falcon *falcon, void *data, u32 start,
                      u32 size, u8 port)
 {
+       mutex_lock(&falcon->dmem_mutex);
+
        falcon->func->load_dmem(falcon, data, start, size, port);
+
+       mutex_unlock(&falcon->dmem_mutex);
 }
 
 void
 nvkm_falcon_read_dmem(struct nvkm_falcon *falcon, u32 start, u32 size, u8 port,
                      void *data)
 {
+       mutex_lock(&falcon->dmem_mutex);
+
        falcon->func->read_dmem(falcon, start, size, port, data);
+
+       mutex_unlock(&falcon->dmem_mutex);
 }
 
 void
@@ -166,6 +174,7 @@ nvkm_falcon_ctor(const struct nvkm_falcon_func *func,
        falcon->name = name;
        falcon->addr = addr;
        mutex_init(&falcon->mutex);
+       mutex_init(&falcon->dmem_mutex);
 
        reg = nvkm_falcon_rd32(falcon, 0x12c);
        falcon->version = reg & 0xf;