drm/virtio: fix virtio-gpu resource id creation race
Subsystems (3)
PATCH 1/1 drm/virtio: fix virtio-gpu resource id creation race
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.
---
drivers/gpu/drm/virtio/virtgpu_object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_object.c +2 -2
@@ -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 );
Signature · 6 lines
2.25.0.265.gbab2e86ba0-goog _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 28 lines · John Bates
The previous code was not thread safe and caused undefined behavior from spurious duplicate resource IDs. In this patch, an
atomic_tis used instead. We no longer see any duplicate IDs in tests with this change.Signed-off-by John Bates <[email protected]>---
drivers/gpu/drm/virtio/virtgpu_object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/virtio/virtgpu_object.c +2
-2@@ -42,8 +42,8 @@ static int virtio_gpu_resource_id_get(structvirtio_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);
Quoted 4 lines
--
2.25.0.265.gbab2e86ba0-goog
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gurchetan Singh
reviewerQuoted 16 lines · John Bates
Quoted 12 lines · John Bates
The previous code was not thread safe and caused undefined behavior from spurious duplicate resource IDs. In this patch, an
atomic_tis used instead. We no longer see any duplicate IDs in tests with this change.Signed-off-by John Bates <[email protected]>---
drivers/gpu/drm/virtio/virtgpu_object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 11 lines
drivers/gpu/drm/virtio/virtgpu_object.c static int virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev, · line 45
Quoted 11 lines
drivers/gpu/drm/virtio/virtgpu_object.c +1
-2@@ -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;
nit: ATOMIC_INIT(0)?
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_object.c +1
-1+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
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi John,
Quoted 7 lines · John Bates
The previous code was not thread safe and caused undefined behavior from spurious duplicate resource IDs. In this patch, an
atomic_tis used instead. We no longer see any duplicate IDs in tests with this change.Signed-off-by John Bates <[email protected]>
Adding a fixes tag like below makes it easier to track. Especially for Greg and team who are working on stable kernels.
switchable.")
HTH
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Chia-I Wu
reviewerQuoted 10 lines · Emil Velikov
Hi John,
Quoted 6 lines · John Bates
The previous code was not thread safe and caused undefined behavior from spurious duplicate resource IDs. In this patch, an
atomic_tis used instead. We no longer see any duplicate IDs in tests with this change.
Quoted 6 lines
Quoted 1 line
Signed-off-by John Bates <[email protected]>Adding a fixes tag like below makes it easier to track. Especially for Greg and team who are working on stable kernels.
Fixes 3e93bc2a58aa ("drm/virtio: make resource id workaround runtimeswitchable.")
FWIW, the fixes tag should refer to this commit instead
commit 16065fcdd19ddb9e093192914ac863884f308766
Author: Gerd Hoffmann <[email protected]> Date: Fri Feb 8 15:04:09 2019 +0100
drm/virtio: do NOT reuse resource ids
Quoted 7 lines
HTH
Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel