<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 21, 2020 at 10:37 AM Chia-I Wu <<a href="mailto:olvaffe@gmail.com">olvaffe@gmail.com</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">On Fri, Feb 21, 2020 at 3:14 AM John Bates <<a href="mailto:jbates@chromium.org" target="_blank">jbates@chromium.org</a>> wrote:<br>
><br>
> 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>
> Fixes: 16065fcdd19d ("drm/virtio: do NOT reuse resource ids")<br>
> Signed-off-by: John Bates <<a href="mailto:jbates@chromium.org" target="_blank">jbates@chromium.org</a>><br>
Reviewed-by: Chia-I Wu <<a href="mailto:olvaffe@gmail.com" target="_blank">olvaffe@gmail.com</a>><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..890121a45625 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 = ATOMIC_INIT(0);<br>
> + int handle = atomic_inc_return(&seqno);<br>
> *resid = handle + 1;<br>
resid 1 is (was) discriminated :D<br></blockquote><div><br></div><div>Yup, noticed that too :)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> } else {<br>
> int handle = ida_alloc(&vgdev->resource_ida, GFP_KERNEL);<br>
> --<br>
> 2.25.0.265.gbab2e86ba0-goog<br>
><br>
> _______________________________________________<br>
> dri-devel mailing list<br>
> <a href="mailto:dri-devel@lists.freedesktop.org" target="_blank">dri-devel@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/dri-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/dri-devel</a><br>
</blockquote></div></div>