* [PATCH v2] drm/virtio: fix resource id creation race
@ 2020-02-20 22:53 John Bates
2020-02-21 18:37 ` Chia-I Wu
2020-02-24 15:07 ` Gerd Hoffmann
0 siblings, 2 replies; 4+ messages in thread
From: John Bates @ 2020-02-20 22:53 UTC (permalink / raw)
To: dri-devel; +Cc: David Airlie, Gurchetan Singh, Gerd Hoffmann, John Bates
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.
Fixes: 16065fcdd19d ("drm/virtio: do NOT reuse resource ids")
Signed-off-by: John Bates <jbates@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..890121a45625 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 = ATOMIC_INIT(0);
+ 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
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] drm/virtio: fix resource id creation race
2020-02-20 22:53 [PATCH v2] drm/virtio: fix resource id creation race John Bates
@ 2020-02-21 18:37 ` Chia-I Wu
2020-02-21 18:48 ` John Bates
2020-02-24 15:07 ` Gerd Hoffmann
1 sibling, 1 reply; 4+ messages in thread
From: Chia-I Wu @ 2020-02-21 18:37 UTC (permalink / raw)
To: John Bates; +Cc: David Airlie, Gerd Hoffmann, ML dri-devel, Gurchetan Singh
On Fri, Feb 21, 2020 at 3:14 AM John Bates <jbates@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.
>
> Fixes: 16065fcdd19d ("drm/virtio: do NOT reuse resource ids")
> Signed-off-by: John Bates <jbates@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
> ---
> 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..890121a45625 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 = ATOMIC_INIT(0);
> + int handle = atomic_inc_return(&seqno);
> *resid = handle + 1;
resid 1 is (was) discriminated :D
> } else {
> int handle = ida_alloc(&vgdev->resource_ida, GFP_KERNEL);
> --
> 2.25.0.265.gbab2e86ba0-goog
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] drm/virtio: fix resource id creation race
2020-02-21 18:37 ` Chia-I Wu
@ 2020-02-21 18:48 ` John Bates
0 siblings, 0 replies; 4+ messages in thread
From: John Bates @ 2020-02-21 18:48 UTC (permalink / raw)
To: Chia-I Wu
Cc: David Airlie, Gerd Hoffmann, ML dri-devel, John Bates, Gurchetan Singh
[-- Attachment #1.1: Type: text/plain, Size: 1773 bytes --]
On Fri, Feb 21, 2020 at 10:37 AM Chia-I Wu <olvaffe@gmail.com> wrote:
> On Fri, Feb 21, 2020 at 3:14 AM John Bates <jbates@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.
> >
> > Fixes: 16065fcdd19d ("drm/virtio: do NOT reuse resource ids")
> > Signed-off-by: John Bates <jbates@chromium.org>
> Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
> > ---
> > 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..890121a45625 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 = ATOMIC_INIT(0);
> > + int handle = atomic_inc_return(&seqno);
> > *resid = handle + 1;
> resid 1 is (was) discriminated :D
>
Yup, noticed that too :)
>
> > } else {
> > int handle = ida_alloc(&vgdev->resource_ida, GFP_KERNEL);
> > --
> > 2.25.0.265.gbab2e86ba0-goog
> >
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
>
[-- Attachment #1.2: Type: text/html, Size: 2930 bytes --]
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] drm/virtio: fix resource id creation race
2020-02-20 22:53 [PATCH v2] drm/virtio: fix resource id creation race John Bates
2020-02-21 18:37 ` Chia-I Wu
@ 2020-02-24 15:07 ` Gerd Hoffmann
1 sibling, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2020-02-24 15:07 UTC (permalink / raw)
To: John Bates; +Cc: David Airlie, dri-devel, Gurchetan Singh
On Thu, Feb 20, 2020 at 02:53:19PM -0800, John Bates 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.
>
> Fixes: 16065fcdd19d ("drm/virtio: do NOT reuse resource ids")
> Signed-off-by: John Bates <jbates@chromium.org>
Pushed to drm-misc-fixes.
thanks,
Gerd
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-02-24 15:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-20 22:53 [PATCH v2] drm/virtio: fix resource id creation race John Bates
2020-02-21 18:37 ` Chia-I Wu
2020-02-21 18:48 ` John Bates
2020-02-24 15:07 ` Gerd Hoffmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.