Skip to content

Commit 25d2b1b

Browse files
David Rileygregkh
authored andcommitted
drm/virtio: Add memory barriers for capset cache.
[ Upstream commit 9ff3a5c ] After data is copied to the cache entry, atomic_set is used indicate that the data is the entry is valid without appropriate memory barriers. Similarly the read side was missing the corresponding memory barriers. Signed-off-by: David Riley <davidriley@chromium.org> Link: http://patchwork.freedesktop.org/patch/msgid/20190610211810.253227-5-davidriley@chromium.org Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent e14829d commit 25d2b1b

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

drivers/gpu/drm/virtio/virtgpu_ioctl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,9 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev,
535535
ret = wait_event_timeout(vgdev->resp_wq,
536536
atomic_read(&cache_ent->is_valid), 5 * HZ);
537537

538+
/* is_valid check must proceed before copy of the cache entry. */
539+
smp_rmb();
540+
538541
ptr = cache_ent->caps_cache;
539542

540543
copy_exit:

drivers/gpu/drm/virtio/virtgpu_vq.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,8 @@ static void virtio_gpu_cmd_capset_cb(struct virtio_gpu_device *vgdev,
618618
cache_ent->id == le32_to_cpu(cmd->capset_id)) {
619619
memcpy(cache_ent->caps_cache, resp->capset_data,
620620
cache_ent->size);
621+
/* Copy must occur before is_valid is signalled. */
622+
smp_wmb();
621623
atomic_set(&cache_ent->is_valid, 1);
622624
break;
623625
}

0 commit comments

Comments
 (0)