Skip to content

Commit

Permalink
drm/nouveau: Add a dedicated mutex for the clients list
Browse files Browse the repository at this point in the history
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: [email protected] # 5.4+
Signed-off-by: Jeremy Cline <[email protected]>
Reviewed-by: Lyude Paul <[email protected]>
Reviewed-by: Ben Skeggs <[email protected]>
Tested-by: Karol Herbst <[email protected]>
Signed-off-by: Karol Herbst <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
Link: https://gitlab.freedesktop.org/drm/nouveau/-/merge_requests/14
  • Loading branch information
jeremycline authored and karolherbst committed Nov 4, 2021
1 parent aff2299 commit abae916
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions drivers/gpu/drm/nouveau/nouveau_drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ nouveau_drm_device_init(struct drm_device *dev)
nvkm_dbgopt(nouveau_debug, "DRM");

INIT_LIST_HEAD(&drm->clients);
mutex_init(&drm->clients_lock);
spin_lock_init(&drm->tile.lock);

/* workaround an odd issue on nvc1 by disabling the device's
Expand Down Expand Up @@ -659,6 +660,7 @@ nouveau_drm_device_fini(struct drm_device *dev)
nouveau_cli_fini(&drm->client);
nouveau_cli_fini(&drm->master);
nvif_parent_dtor(&drm->parent);
mutex_destroy(&drm->clients_lock);
kfree(drm);
}

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

fpriv->driver_priv = cli;

mutex_lock(&drm->client.mutex);
mutex_lock(&drm->clients_lock);
list_add(&cli->head, &drm->clients);
mutex_unlock(&drm->client.mutex);
mutex_unlock(&drm->clients_lock);

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

mutex_lock(&drm->client.mutex);
mutex_lock(&drm->clients_lock);
list_del(&cli->head);
mutex_unlock(&drm->client.mutex);
mutex_unlock(&drm->clients_lock);

nouveau_cli_fini(cli);
kfree(cli);
Expand Down
5 changes: 5 additions & 0 deletions drivers/gpu/drm/nouveau/nouveau_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ struct nouveau_drm {

struct list_head clients;

/**
* @clients_lock: Protects access to the @clients list of &struct nouveau_cli.
*/
struct mutex clients_lock;

u8 old_pm_cap;

struct {
Expand Down

0 comments on commit abae916

Please sign in to comment.