* [PATCH] drm/virtio: fix virtio-gpu resource id creation race
@ 2020-02-19 20:40 John Bates
2020-02-20 0:19 ` John Bates
2020-02-20 13:30 ` Emil Velikov
0 siblings, 2 replies; 5+ messages in thread
From: John Bates @ 2020-02-19 20:40 UTC (permalink / raw)
To: dri-devel; +Cc: David Airlie, John Bates, Gerd Hoffmann, Gurchetan Singh
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@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
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] drm/virtio: fix virtio-gpu resource id creation race
2020-02-19 20:40 [PATCH] drm/virtio: fix virtio-gpu resource id creation race John Bates
@ 2020-02-20 0:19 ` John Bates
2020-02-20 0:38 ` Gurchetan Singh
2020-02-20 13:30 ` Emil Velikov
1 sibling, 1 reply; 5+ messages in thread
From: John Bates @ 2020-02-20 0:19 UTC (permalink / raw)
To: John Bates; +Cc: David Airlie, dri-devel, Gurchetan Singh, Gerd Hoffmann
[-- Attachment #1.1: Type: text/plain, Size: 1272 bytes --]
On Wed, Feb 19, 2020 at 12:40 PM 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.
>
> 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..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
>
>
[-- Attachment #1.2: Type: text/html, Size: 1808 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] 5+ messages in thread
* Re: [PATCH] drm/virtio: fix virtio-gpu resource id creation race
2020-02-20 0:19 ` John Bates
@ 2020-02-20 0:38 ` Gurchetan Singh
0 siblings, 0 replies; 5+ messages in thread
From: Gurchetan Singh @ 2020-02-20 0:38 UTC (permalink / raw)
To: John Bates; +Cc: John Bates, David Airlie, ML dri-devel, Gerd Hoffmann
On Wed, Feb 19, 2020 at 4:20 PM John Bates <jbates@google.com> wrote:
>
>
>
> On Wed, Feb 19, 2020 at 12:40 PM 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.
>>
>> 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..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;
nit: 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 [flat|nested] 5+ messages in thread
* Re: [PATCH] drm/virtio: fix virtio-gpu resource id creation race
2020-02-19 20:40 [PATCH] drm/virtio: fix virtio-gpu resource id creation race John Bates
2020-02-20 0:19 ` John Bates
@ 2020-02-20 13:30 ` Emil Velikov
2020-02-20 18:22 ` Chia-I Wu
1 sibling, 1 reply; 5+ messages in thread
From: Emil Velikov @ 2020-02-20 13:30 UTC (permalink / raw)
To: John Bates; +Cc: David Airlie, Gerd Hoffmann, ML dri-devel, Gurchetan Singh
Hi John,
On Thu, 20 Feb 2020 at 08:45, 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.
>
> Signed-off-by: John Bates <jbates@chromium.org>
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 runtime
switchable.")
HTH
Emil
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] drm/virtio: fix virtio-gpu resource id creation race
2020-02-20 13:30 ` Emil Velikov
@ 2020-02-20 18:22 ` Chia-I Wu
0 siblings, 0 replies; 5+ messages in thread
From: Chia-I Wu @ 2020-02-20 18:22 UTC (permalink / raw)
To: Emil Velikov
Cc: David Airlie, ML dri-devel, Gerd Hoffmann, John Bates, Gurchetan Singh
On Thu, Feb 20, 2020 at 5:30 AM Emil Velikov <emil.l.velikov@gmail.com> wrote:
>
> Hi John,
>
> On Thu, 20 Feb 2020 at 08:45, 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.
> >
> > Signed-off-by: John Bates <jbates@chromium.org>
> 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 runtime
> switchable.")
FWIW, the fixes tag should refer to this commit instead
commit 16065fcdd19ddb9e093192914ac863884f308766
Author: Gerd Hoffmann <kraxel@redhat.com>
Date: Fri Feb 8 15:04:09 2019 +0100
drm/virtio: do NOT reuse resource ids
>
> HTH
> Emil
> _______________________________________________
> 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] 5+ messages in thread
end of thread, other threads:[~2020-02-20 18:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-19 20:40 [PATCH] drm/virtio: fix virtio-gpu resource id creation race John Bates
2020-02-20 0:19 ` John Bates
2020-02-20 0:38 ` Gurchetan Singh
2020-02-20 13:30 ` Emil Velikov
2020-02-20 18:22 ` Chia-I Wu
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.