Skip to content

Commit

Permalink
DRM[i915]: fix i915 crash during reboot stress test
Browse files Browse the repository at this point in the history
Use drm_release with global spinlock to make sure memtrack file create/close
is serialization, and if sysfs_create_bin_file return file existed error, need to
return 0 to let open drm process move forward

Tracked-On: OAM-128000
Signed-off-by: Kui Wen <[email protected]>
  • Loading branch information
beckwen authored and sysopenci committed Dec 11, 2024
1 parent e4c7a16 commit bd445d6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
3 changes: 3 additions & 0 deletions drivers/gpu/drm/i915/gem/i915_gem_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,9 @@ static void gem_context_register(struct i915_gem_context *ctx,
snprintf(ctx->name, sizeof(ctx->name), "%s[%d]",
current->comm, pid_nr(ctx->pid));

if (ctx->client == NULL)
return ;

spin_lock(&ctx->client->ctx_lock);
list_add_tail_rcu(&ctx->client_link, &ctx->client->ctx_list);
spin_unlock(&ctx->client->ctx_lock);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/i915_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1772,7 +1772,7 @@ const struct dev_pm_ops i915_pm_ops = {
static const struct file_operations i915_driver_fops = {
.owner = THIS_MODULE,
.open = drm_open,
.release = drm_release_noglobal,
.release = drm_release,
.unlocked_ioctl = drm_ioctl,
.mmap = i915_gem_mmap,
.poll = drm_poll,
Expand Down
12 changes: 5 additions & 7 deletions drivers/gpu/drm/i915/i915_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ int i915_gem_create_sysfs_file_entry(struct drm_device *dev,
struct drm_i915_file_private *file_priv_local =
file_local->driver_priv;

if (pid_nr(file_priv->tgid) == pid_nr(file_priv_local->tgid)) {
if ((pid_nr(file_priv->tgid) == pid_nr(file_priv_local->tgid)) && (file_priv_local->obj_attr != NULL)) {
file_priv->obj_attr = file_priv_local->obj_attr;
mutex_unlock(&dev->filelist_mutex);
return 0;
Expand Down Expand Up @@ -447,6 +447,8 @@ int i915_gem_create_sysfs_file_entry(struct drm_device *dev,
DRM_ERROR(
"sysfs tgid file setup failed. tgid=%d, process:%s, ret:%d\n",
pid_nr(file_priv->tgid), file_priv->process_name, ret);
if (ret == -EEXIST)
ret = 0;
goto out_attr_priv;
}

Expand Down Expand Up @@ -486,16 +488,15 @@ void i915_gem_remove_sysfs_file_entry(struct drm_device *dev,
}
mutex_unlock(&dev->filelist_mutex);

mutex_lock(&drm_global_mutex);
if (open_count == 1) {
struct i915_gem_file_attr_priv *attr_priv;

if (file_priv->obj_attr == NULL)
goto out;
return;

attr_priv = file_priv->obj_attr->private;
if (attr_priv == NULL)
goto out;
return;

sysfs_remove_bin_file(&dev_priv->memtrack_kobj,
file_priv->obj_attr);
Expand All @@ -506,9 +507,6 @@ void i915_gem_remove_sysfs_file_entry(struct drm_device *dev,
kfree(file_priv->obj_attr);
file_priv->obj_attr = NULL;
}

out:
mutex_unlock(&drm_global_mutex);
}

static struct bin_attribute i915_gem_client_state_attr = {
Expand Down

0 comments on commit bd445d6

Please sign in to comment.