Commit 621bd0f6 authored by Daniel Vetter's avatar Daniel Vetter Committed by Dave Airlie

drm: Fix locking for sysfs dpms file

With atomic drivers we need to make sure that (at least in general)
property reads hold the right locks. But the legacy dpms property is
special and can be read locklessly. Since userspace loves to just
randomly look at that all the time (like with "status") do that.

To make it clear that we play tricks use the READ_ONCE compiler
barrier (and also for paranoia).

Note that there's not really anything bad going on since even with the
new atomic paths we eventually end up not chasing any pointers (and
hence possibly freed memory and other fun stuff). The locking WARNING
has been added in

commit 88a48e29
Author: Rob Clark <robdclark@gmail.com>
Date:   Thu Dec 18 16:01:50 2014 -0500

    drm: add atomic properties

but since drivers are converting not everyone will have seen this from
the start.

Jens reported this and submitted a patch to just grab the
mode_config.connection_mutex, but we can do a bit better.

v2: Remove unused variables I failed to git add for real.

Reference: http://mid.gmane.org/20150928194822.GA3930@kernel.dkReported-by: default avatarJens Axboe <axboe@fb.com>
Tested-by: default avatarJens Axboe <axboe@fb.com>
Cc: Rob Clark <robdclark@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent e87d68dd
...@@ -235,18 +235,12 @@ static ssize_t dpms_show(struct device *device, ...@@ -235,18 +235,12 @@ static ssize_t dpms_show(struct device *device,
char *buf) char *buf)
{ {
struct drm_connector *connector = to_drm_connector(device); struct drm_connector *connector = to_drm_connector(device);
struct drm_device *dev = connector->dev; int dpms;
uint64_t dpms_status;
int ret;
ret = drm_object_property_get_value(&connector->base, dpms = READ_ONCE(connector->dpms);
dev->mode_config.dpms_property,
&dpms_status);
if (ret)
return 0;
return snprintf(buf, PAGE_SIZE, "%s\n", return snprintf(buf, PAGE_SIZE, "%s\n",
drm_get_dpms_name((int)dpms_status)); drm_get_dpms_name(dpms));
} }
static ssize_t enabled_show(struct device *device, static ssize_t enabled_show(struct device *device,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment