<div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 19, 2020 at 12:40 PM John Bates <<a href="mailto:jbates@chromium.org">jbates@chromium.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The previous code was not thread safe and caused<br>
undefined behavior from spurious duplicate resource IDs.<br>
In this patch, an atomic_t is used instead. We no longer<br>
see any duplicate IDs in tests with this change.<br>
<br>
Signed-off-by: John Bates <<a href="mailto:jbates@chromium.org" target="_blank">jbates@chromium.org</a>><br>
---<br>
<br>
drivers/gpu/drm/virtio/virtgpu_object.c | 4 ++--<br>
1 file changed, 2 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c<br>
index 017a9e0fc3bb..b11c1fce1770 100644<br>
--- a/drivers/gpu/drm/virtio/virtgpu_object.c<br>
+++ b/drivers/gpu/drm/virtio/virtgpu_object.c<br>
@@ -42,8 +42,8 @@ static int virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,<br>
* "f91a9dd35715 Fix unlinking resources from hash<br>
* table." (Feb 2019) fixes the bug.<br>
*/<br>
- static int handle;<br>
- handle++;<br>
+ static atomic_t seqno;<br>
+ int handle = atomic_inc_return(&seqno);<br>
*resid = handle + 1;<br>
} else {<br>
int handle = ida_alloc(&vgdev->resource_ida, GFP_KERNEL);<br>
-- <br>
2.25.0.265.gbab2e86ba0-goog<br>
<br>
</blockquote></div>