[PATCH] drm/virtio: fix virtio-gpu resource id creation race

John Bates jbates at google.com
Thu Feb 20 00:19:48 UTC 2020


On Wed, Feb 19, 2020 at 12:40 PM John Bates <jbates at chromium.org> wrote:

> The previous code was not thread safe and caused
> undefined behavior from spurious duplicate resource IDs.
> In this patch, an atomic_t is used instead. We no longer
> see any duplicate IDs in tests with this change.
>
> Signed-off-by: John Bates <jbates at chromium.org>
> ---
>
>  drivers/gpu/drm/virtio/virtgpu_object.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c
> b/drivers/gpu/drm/virtio/virtgpu_object.c
> index 017a9e0fc3bb..b11c1fce1770 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_object.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_object.c
> @@ -42,8 +42,8 @@ static int virtio_gpu_resource_id_get(struct
> virtio_gpu_device *vgdev,
>                  * "f91a9dd35715 Fix unlinking resources from hash
>                  * table." (Feb 2019) fixes the bug.
>                  */
> -               static int handle;
> -               handle++;
> +               static atomic_t seqno;
> +               int handle = atomic_inc_return(&seqno);
>                 *resid = handle + 1;
>         } else {
>                 int handle = ida_alloc(&vgdev->resource_ida, GFP_KERNEL);
> --
> 2.25.0.265.gbab2e86ba0-goog
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/dri-devel/attachments/20200219/6bf274bb/attachment-0001.htm>


More information about the dri-devel mailing list