Skip to content

Commit abae916

Browse files
jeremyclinekarolherbst
authored andcommitted
drm/nouveau: Add a dedicated mutex for the clients list
Rather than protecting the nouveau_drm clients list with the lock within the "client" nouveau_cli, add a dedicated lock to serialize access to the list. This is both clearer and necessary to avoid lockdep being upset with us when we need to iterate through all the clients in the list and potentially lock their mutex, which is the same class as the lock protecting the entire list. Cc: stable@vger.kernel.org # 5.4+ Signed-off-by: Jeremy Cline <jcline@redhat.com> Reviewed-by: Lyude Paul <lyude@redhat.com> Reviewed-by: Ben Skeggs <bskeggs@redhat.com> Tested-by: Karol Herbst <kherbst@redhat.com> Signed-off-by: Karol Herbst <kherbst@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20201125202648.5220-3-jcline@redhat.com Link: https://gitlab.freedesktop.org/drm/nouveau/-/merge_requests/14
1 parent aff2299 commit abae916

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

drivers/gpu/drm/nouveau/nouveau_drm.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ nouveau_drm_device_init(struct drm_device *dev)
562562
nvkm_dbgopt(nouveau_debug, "DRM");
563563

564564
INIT_LIST_HEAD(&drm->clients);
565+
mutex_init(&drm->clients_lock);
565566
spin_lock_init(&drm->tile.lock);
566567

567568
/* workaround an odd issue on nvc1 by disabling the device's
@@ -659,6 +660,7 @@ nouveau_drm_device_fini(struct drm_device *dev)
659660
nouveau_cli_fini(&drm->client);
660661
nouveau_cli_fini(&drm->master);
661662
nvif_parent_dtor(&drm->parent);
663+
mutex_destroy(&drm->clients_lock);
662664
kfree(drm);
663665
}
664666

@@ -1090,9 +1092,9 @@ nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv)
10901092

10911093
fpriv->driver_priv = cli;
10921094

1093-
mutex_lock(&drm->client.mutex);
1095+
mutex_lock(&drm->clients_lock);
10941096
list_add(&cli->head, &drm->clients);
1095-
mutex_unlock(&drm->client.mutex);
1097+
mutex_unlock(&drm->clients_lock);
10961098

10971099
done:
10981100
if (ret && cli) {
@@ -1118,9 +1120,9 @@ nouveau_drm_postclose(struct drm_device *dev, struct drm_file *fpriv)
11181120
nouveau_abi16_fini(cli->abi16);
11191121
mutex_unlock(&cli->mutex);
11201122

1121-
mutex_lock(&drm->client.mutex);
1123+
mutex_lock(&drm->clients_lock);
11221124
list_del(&cli->head);
1123-
mutex_unlock(&drm->client.mutex);
1125+
mutex_unlock(&drm->clients_lock);
11241126

11251127
nouveau_cli_fini(cli);
11261128
kfree(cli);

drivers/gpu/drm/nouveau/nouveau_drv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ struct nouveau_drm {
139139

140140
struct list_head clients;
141141

142+
/**
143+
* @clients_lock: Protects access to the @clients list of &struct nouveau_cli.
144+
*/
145+
struct mutex clients_lock;
146+
142147
u8 old_pm_cap;
143148

144149
struct {

0 commit comments

Comments
 (0)