2017-06-09 21:31:11

by Andrey Grodzovsky

[permalink] [raw]
Subject: [PATCH] drm/core: Fail atomic IOCTL with no CRTC state but with signaling.

Problem:
While running IGT kms_atomic_transition test suite i encountered
a hang in drmHandleEvent immidietly follwoing an atomic_commit.
After dumping the atomic state I relized that in this case there was
not even one CRTC attached to the state and only disabled
planes. This probably due to a commit which hadn't changed any property
which would require attaching crtc state. This means drmHandleEvent
will never wake up from read since without CRTC in atomic state
the event fd will not be singnaled.
This point to a bug in IGT but also DRM should gracefully
fail such scenario so no hang on user side will happen.

Fix:
Explicitly fail by failing atomic_commit early in
drm_mode_atomic_commit where such problem can be identified.

Signed-off-by: Andrey Grodzovsky <[email protected]>
---
drivers/gpu/drm/drm_atomic.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index a567310..32eae1c 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -1933,7 +1933,7 @@ static int prepare_crtc_signaling(struct drm_device *dev,
{
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
- int i, ret;
+ int i, c = 0, ret;

if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)
return 0;
@@ -1994,8 +1994,17 @@ static int prepare_crtc_signaling(struct drm_device *dev,

crtc_state->event->base.fence = fence;
}
+
+ c++;
}

+ /*
+ * Having this flag means user mode pends on event which will never
+ * reach due to lack of at least one CRTC for signaling
+ */
+ if (c == 0 && (arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
+ return -EINVAL;
+
return 0;
}

@@ -2179,6 +2188,8 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
drm_mode_object_unreference(obj);
}

+
+
ret = prepare_crtc_signaling(dev, state, arg, file_priv, &fence_state,
&num_fences);
if (ret)
--
2.7.4


2017-06-12 11:08:09

by Maarten Lankhorst

[permalink] [raw]
Subject: Re: [PATCH] drm/core: Fail atomic IOCTL with no CRTC state but with signaling.

Op 09-06-17 om 23:30 schreef Andrey Grodzovsky:
> Problem:
> While running IGT kms_atomic_transition test suite i encountered
> a hang in drmHandleEvent immidietly follwoing an atomic_commit.
> After dumping the atomic state I relized that in this case there was
> not even one CRTC attached to the state and only disabled
> planes. This probably due to a commit which hadn't changed any property
> which would require attaching crtc state. This means drmHandleEvent
> will never wake up from read since without CRTC in atomic state
> the event fd will not be singnaled.
> This point to a bug in IGT but also DRM should gracefully
> fail such scenario so no hang on user side will happen.
>
> Fix:
> Explicitly fail by failing atomic_commit early in
> drm_mode_atomic_commit where such problem can be identified.
>
> Signed-off-by: Andrey Grodzovsky <[email protected]>
> ---
> drivers/gpu/drm/drm_atomic.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
Patch itself looks sane, but I'm worried about failing with -EINVAL when the same configuration with TEST_ONLY would otherwise succeed on it.
Not sure whether we should fail or not, since sending 0 events could still be considered success.

I don't mind either way, but definitely something that should be discussed before applying.

2017-06-12 14:12:32

by Andrey Grodzovsky

[permalink] [raw]
Subject: Re: [PATCH] drm/core: Fail atomic IOCTL with no CRTC state but with signaling.



On 06/12/2017 07:08 AM, Maarten Lankhorst wrote:
> Op 09-06-17 om 23:30 schreef Andrey Grodzovsky:
>> Problem:
>> While running IGT kms_atomic_transition test suite i encountered
>> a hang in drmHandleEvent immidietly follwoing an atomic_commit.
>> After dumping the atomic state I relized that in this case there was
>> not even one CRTC attached to the state and only disabled
>> planes. This probably due to a commit which hadn't changed any property
>> which would require attaching crtc state. This means drmHandleEvent
>> will never wake up from read since without CRTC in atomic state
>> the event fd will not be singnaled.
>> This point to a bug in IGT but also DRM should gracefully
>> fail such scenario so no hang on user side will happen.
>>
>> Fix:
>> Explicitly fail by failing atomic_commit early in
>> drm_mode_atomic_commit where such problem can be identified.
>>
>> Signed-off-by: Andrey Grodzovsky <[email protected]>
>> ---
>> drivers/gpu/drm/drm_atomic.c | 13 ++++++++++++-
>> 1 file changed, 12 insertions(+), 1 deletion(-)
> Patch itself looks sane, but I'm worried about failing with -EINVAL when the same configuration with TEST_ONLY would otherwise succeed on it.
DRM_MODE_ATOMIC_TEST_ONLY flag is checked later, after this, so if this
fails , test only will return EINVAL also.
> Not sure whether we should fail or not, since sending 0 events could still be considered success.
>
> I don't mind either way, but definitely something that should be discussed before applying.
Sending 0 events is no problem at all on it's own but if user provides
DRM_MODE_PAGE_FLIP_EVENT in args
then when it becomes a problem , doesn't it mean he expects to receive
at least one event ?

Thanks.

2017-06-15 20:46:57

by Andrey Grodzovsky

[permalink] [raw]
Subject: Re: [PATCH] drm/core: Fail atomic IOCTL with no CRTC state but with signaling.

Just a reminder.

Thanks.

On 06/09/2017 05:30 PM, Andrey Grodzovsky wrote:
> Problem:
> While running IGT kms_atomic_transition test suite i encountered
> a hang in drmHandleEvent immidietly follwoing an atomic_commit.
> After dumping the atomic state I relized that in this case there was
> not even one CRTC attached to the state and only disabled
> planes. This probably due to a commit which hadn't changed any property
> which would require attaching crtc state. This means drmHandleEvent
> will never wake up from read since without CRTC in atomic state
> the event fd will not be singnaled.
> This point to a bug in IGT but also DRM should gracefully
> fail such scenario so no hang on user side will happen.
>
> Fix:
> Explicitly fail by failing atomic_commit early in
> drm_mode_atomic_commit where such problem can be identified.
>
> Signed-off-by: Andrey Grodzovsky <[email protected]>
> ---
> drivers/gpu/drm/drm_atomic.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index a567310..32eae1c 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -1933,7 +1933,7 @@ static int prepare_crtc_signaling(struct drm_device *dev,
> {
> struct drm_crtc *crtc;
> struct drm_crtc_state *crtc_state;
> - int i, ret;
> + int i, c = 0, ret;
>
> if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)
> return 0;
> @@ -1994,8 +1994,17 @@ static int prepare_crtc_signaling(struct drm_device *dev,
>
> crtc_state->event->base.fence = fence;
> }
> +
> + c++;
> }
>
> + /*
> + * Having this flag means user mode pends on event which will never
> + * reach due to lack of at least one CRTC for signaling
> + */
> + if (c == 0 && (arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
> + return -EINVAL;
> +
> return 0;
> }
>
> @@ -2179,6 +2188,8 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
> drm_mode_object_unreference(obj);
> }
>
> +
> +
> ret = prepare_crtc_signaling(dev, state, arg, file_priv, &fence_state,
> &num_fences);
> if (ret)

2017-06-19 15:35:44

by Harry Wentland

[permalink] [raw]
Subject: Re: [PATCH] drm/core: Fail atomic IOCTL with no CRTC state but with signaling.

On 2017-06-09 05:30 PM, Andrey Grodzovsky wrote:
> Problem:
> While running IGT kms_atomic_transition test suite i encountered
> a hang in drmHandleEvent immidietly follwoing an atomic_commit.

s/immidietly/immediately/g
s/follwoing/following/g

> After dumping the atomic state I relized that in this case there was
> not even one CRTC attached to the state and only disabled
> planes. This probably due to a commit which hadn't changed any property
> which would require attaching crtc state. This means drmHandleEvent
> will never wake up from read since without CRTC in atomic state
> the event fd will not be singnaled.

s/singnaled/signaled/g

> This point to a bug in IGT but also DRM should gracefully
> fail such scenario so no hang on user side will happen.
>

Can we create an IGT fix for this to make sure this won't happen?

> Fix:
> Explicitly fail by failing atomic_commit early in
> drm_mode_atomic_commit where such problem can be identified.
>

The change seems reasonable to me but I would like to see some input
from someone who's more familiar with the usermode side of things.

> Signed-off-by: Andrey Grodzovsky <[email protected]>
> ---
> drivers/gpu/drm/drm_atomic.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index a567310..32eae1c 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -1933,7 +1933,7 @@ static int prepare_crtc_signaling(struct drm_device *dev,
> {
> struct drm_crtc *crtc;
> struct drm_crtc_state *crtc_state;
> - int i, ret;
> + int i, c = 0, ret;
>
> if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)
> return 0;
> @@ -1994,8 +1994,17 @@ static int prepare_crtc_signaling(struct drm_device *dev,
>
> crtc_state->event->base.fence = fence;
> }
> +
> + c++;

Not sure if intentional, but I like it.

> }
>
> + /*
> + * Having this flag means user mode pends on event which will never
> + * reach due to lack of at least one CRTC for signaling
> + */
> + if (c == 0 && (arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
> + return -EINVAL;
> +
> return 0;
> }
>
> @@ -2179,6 +2188,8 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
> drm_mode_object_unreference(obj);
> }
>
> +
> +

Remove these extraneous newlines.

Harry

> ret = prepare_crtc_signaling(dev, state, arg, file_priv, &fence_state,
> &num_fences);
> if (ret)
>

2017-06-19 19:24:35

by Sean Paul

[permalink] [raw]
Subject: Re: [PATCH] drm/core: Fail atomic IOCTL with no CRTC state but with signaling.

On Mon, Jun 19, 2017 at 11:35:28AM -0400, Harry Wentland wrote:
> On 2017-06-09 05:30 PM, Andrey Grodzovsky wrote:
> > Problem:
> > While running IGT kms_atomic_transition test suite i encountered
> > a hang in drmHandleEvent immidietly follwoing an atomic_commit.
>
> s/immidietly/immediately/g
> s/follwoing/following/g
>
> > After dumping the atomic state I relized that in this case there was
> > not even one CRTC attached to the state and only disabled
> > planes. This probably due to a commit which hadn't changed any property
> > which would require attaching crtc state. This means drmHandleEvent
> > will never wake up from read since without CRTC in atomic state
> > the event fd will not be singnaled.
>
> s/singnaled/signaled/g
>
> > This point to a bug in IGT but also DRM should gracefully
> > fail such scenario so no hang on user side will happen.
> >
>
> Can we create an IGT fix for this to make sure this won't happen?
>
> > Fix:
> > Explicitly fail by failing atomic_commit early in
> > drm_mode_atomic_commit where such problem can be identified.
> >
>
> The change seems reasonable to me but I would like to see some input
> from someone who's more familiar with the usermode side of things.

I wonder if there's ever a case where it might be desirable to generate an event
from a commit without a crtc. I don't know if anyone has explicitly said that an
event can only be generated from state with crtc.

I usually don't mind letting userspace shoot itself in the foot, so keep that in
mind :)

Sean


>
> > Signed-off-by: Andrey Grodzovsky <[email protected]>
> > ---
> > drivers/gpu/drm/drm_atomic.c | 13 ++++++++++++-
> > 1 file changed, 12 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> > index a567310..32eae1c 100644
> > --- a/drivers/gpu/drm/drm_atomic.c
> > +++ b/drivers/gpu/drm/drm_atomic.c
> > @@ -1933,7 +1933,7 @@ static int prepare_crtc_signaling(struct drm_device *dev,
> > {
> > struct drm_crtc *crtc;
> > struct drm_crtc_state *crtc_state;
> > - int i, ret;
> > + int i, c = 0, ret;
> >
> > if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)
> > return 0;
> > @@ -1994,8 +1994,17 @@ static int prepare_crtc_signaling(struct drm_device *dev,
> >
> > crtc_state->event->base.fence = fence;
> > }
> > +
> > + c++;
>
> Not sure if intentional, but I like it.
>
> > }
> >
> > + /*
> > + * Having this flag means user mode pends on event which will never
> > + * reach due to lack of at least one CRTC for signaling
> > + */
> > + if (c == 0 && (arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
> > + return -EINVAL;
> > +
> > return 0;
> > }
> >
> > @@ -2179,6 +2188,8 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
> > drm_mode_object_unreference(obj);
> > }
> >
> > +
> > +
>
> Remove these extraneous newlines.
>
> Harry
>
> > ret = prepare_crtc_signaling(dev, state, arg, file_priv, &fence_state,
> > &num_fences);
> > if (ret)
> >

--
Sean Paul, Software Engineer, Google / Chromium OS

2017-06-20 17:57:34

by Andrey Grodzovsky

[permalink] [raw]
Subject: [PATCH v2] drm/core: Fail atomic IOCTL with no CRTC state but with signaling.

Problem : While running IGT kms_atomic_transition test suite i encountered
a hang in drmHandleEvent immediately following an atomic_commit.
After dumping the atomic state I relized that in this case there was
not even one CRTC attached to the state and only disabled
planes. This probably due to a commit which hadn't changed any property
which would require attaching crtc state. This means drmHandleEvent
will never wake up from read since without CRTC in atomic state
the event fd will not be signaled.

Fix: Protect against this issue by failing atomic_commit early in
drm_mode_atomic_commit where such probelm can be identified.

v2:
Fix typos and extra newlines.

Change-Id: I3ee28ffae35fd1e8bfe553146c44da53da02e6f8
Signed-off-by: Andrey Grodzovsky <[email protected]>
---
drivers/gpu/drm/drm_atomic.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index a567310..48145bf 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -1933,7 +1933,7 @@ static int prepare_crtc_signaling(struct drm_device *dev,
{
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
- int i, ret;
+ int i, c = 0, ret;

if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)
return 0;
@@ -1994,8 +1994,17 @@ static int prepare_crtc_signaling(struct drm_device *dev,

crtc_state->event->base.fence = fence;
}
+
+ c++;
}

+ /*
+ * Having this flag means user mode pends on event which will never
+ * reach due to lack of at least one CRTC for signaling
+ */
+ if (c == 0 && (arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
+ return -EINVAL;
+
return 0;
}

--
2.7.4

2017-06-26 19:44:22

by Harry Wentland

[permalink] [raw]
Subject: Re: [PATCH v2] drm/core: Fail atomic IOCTL with no CRTC state but with signaling.

On 2017-06-20 01:57 PM, Andrey Grodzovsky wrote:
> Problem : While running IGT kms_atomic_transition test suite i encountered
> a hang in drmHandleEvent immediately following an atomic_commit.
> After dumping the atomic state I relized that in this case there was
> not even one CRTC attached to the state and only disabled
> planes. This probably due to a commit which hadn't changed any property
> which would require attaching crtc state. This means drmHandleEvent
> will never wake up from read since without CRTC in atomic state
> the event fd will not be signaled.
>
> Fix: Protect against this issue by failing atomic_commit early in
> drm_mode_atomic_commit where such probelm can be identified.
>
> v2:
> Fix typos and extra newlines.
>
> Change-Id: I3ee28ffae35fd1e8bfe553146c44da53da02e6f8
> Signed-off-by: Andrey Grodzovsky <[email protected]>

Reviewed-by: Harry Wentland <[email protected]>

Harry

> ---
> drivers/gpu/drm/drm_atomic.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index a567310..48145bf 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -1933,7 +1933,7 @@ static int prepare_crtc_signaling(struct drm_device *dev,
> {
> struct drm_crtc *crtc;
> struct drm_crtc_state *crtc_state;
> - int i, ret;
> + int i, c = 0, ret;
>
> if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)
> return 0;
> @@ -1994,8 +1994,17 @@ static int prepare_crtc_signaling(struct drm_device *dev,
>
> crtc_state->event->base.fence = fence;
> }
> +
> + c++;
> }
>
> + /*
> + * Having this flag means user mode pends on event which will never
> + * reach due to lack of at least one CRTC for signaling
> + */
> + if (c == 0 && (arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
> + return -EINVAL;
> +
> return 0;
> }
>
>

2017-06-27 07:37:49

by Daniel Vetter

[permalink] [raw]
Subject: Re: [PATCH v2] drm/core: Fail atomic IOCTL with no CRTC state but with signaling.

On Mon, Jun 26, 2017 at 03:44:07PM -0400, Harry Wentland wrote:
> On 2017-06-20 01:57 PM, Andrey Grodzovsky wrote:
> > Problem : While running IGT kms_atomic_transition test suite i encountered
> > a hang in drmHandleEvent immediately following an atomic_commit.
> > After dumping the atomic state I relized that in this case there was
> > not even one CRTC attached to the state and only disabled
> > planes. This probably due to a commit which hadn't changed any property
> > which would require attaching crtc state. This means drmHandleEvent
> > will never wake up from read since without CRTC in atomic state
> > the event fd will not be signaled.
> >
> > Fix: Protect against this issue by failing atomic_commit early in
> > drm_mode_atomic_commit where such probelm can be identified.
> >
> > v2:
> > Fix typos and extra newlines.
> >
> > Change-Id: I3ee28ffae35fd1e8bfe553146c44da53da02e6f8
> > Signed-off-by: Andrey Grodzovsky <[email protected]>
>
> Reviewed-by: Harry Wentland <[email protected]>

Stalling on this hoping for the igt patch. Does it exist already?
-Daniel

>
> Harry
>
> > ---
> > drivers/gpu/drm/drm_atomic.c | 11 ++++++++++-
> > 1 file changed, 10 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> > index a567310..48145bf 100644
> > --- a/drivers/gpu/drm/drm_atomic.c
> > +++ b/drivers/gpu/drm/drm_atomic.c
> > @@ -1933,7 +1933,7 @@ static int prepare_crtc_signaling(struct drm_device *dev,
> > {
> > struct drm_crtc *crtc;
> > struct drm_crtc_state *crtc_state;
> > - int i, ret;
> > + int i, c = 0, ret;
> >
> > if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)
> > return 0;
> > @@ -1994,8 +1994,17 @@ static int prepare_crtc_signaling(struct drm_device *dev,
> >
> > crtc_state->event->base.fence = fence;
> > }
> > +
> > + c++;
> > }
> >
> > + /*
> > + * Having this flag means user mode pends on event which will never
> > + * reach due to lack of at least one CRTC for signaling
> > + */
> > + if (c == 0 && (arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
> > + return -EINVAL;
> > +
> > return 0;
> > }
> >
> >

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

2017-06-27 14:30:15

by Maarten Lankhorst

[permalink] [raw]
Subject: Re: [PATCH v2] drm/core: Fail atomic IOCTL with no CRTC state but with signaling.

Op 27-06-17 om 09:37 schreef Daniel Vetter:
> On Mon, Jun 26, 2017 at 03:44:07PM -0400, Harry Wentland wrote:
>> On 2017-06-20 01:57 PM, Andrey Grodzovsky wrote:
>>> Problem : While running IGT kms_atomic_transition test suite i encountered
>>> a hang in drmHandleEvent immediately following an atomic_commit.
>>> After dumping the atomic state I relized that in this case there was
>>> not even one CRTC attached to the state and only disabled
>>> planes. This probably due to a commit which hadn't changed any property
>>> which would require attaching crtc state. This means drmHandleEvent
>>> will never wake up from read since without CRTC in atomic state
>>> the event fd will not be signaled.
>>>
>>> Fix: Protect against this issue by failing atomic_commit early in
>>> drm_mode_atomic_commit where such probelm can be identified.
>>>
>>> v2:
>>> Fix typos and extra newlines.
>>>
>>> Change-Id: I3ee28ffae35fd1e8bfe553146c44da53da02e6f8
>>> Signed-off-by: Andrey Grodzovsky <[email protected]>
>> Reviewed-by: Harry Wentland <[email protected]>
> Stalling on this hoping for the igt patch. Does it exist already?
> -Daniel
>
>> Harry
>>
>>> ---
>>> drivers/gpu/drm/drm_atomic.c | 11 ++++++++++-
>>> 1 file changed, 10 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
>>> index a567310..48145bf 100644
>>> --- a/drivers/gpu/drm/drm_atomic.c
>>> +++ b/drivers/gpu/drm/drm_atomic.c
>>> @@ -1933,7 +1933,7 @@ static int prepare_crtc_signaling(struct drm_device *dev,
>>> {
>>> struct drm_crtc *crtc;
>>> struct drm_crtc_state *crtc_state;
>>> - int i, ret;
>>> + int i, c = 0, ret;
>>>
>>> if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)
>>> return 0;
>>> @@ -1994,8 +1994,17 @@ static int prepare_crtc_signaling(struct drm_device *dev,
>>>
>>> crtc_state->event->base.fence = fence;
>>> }
>>> +
>>> + c++;
>>> }
>>>
>>> + /*
>>> + * Having this flag means user mode pends on event which will never
>>> + * reach due to lack of at least one CRTC for signaling
>>> + */
>>> + if (c == 0 && (arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
>>> + return -EINVAL;
>>> +
>>> return 0;
>>> }
>>>
>>>
Just do it, and I'll commit this to igt?

diff --git a/tests/kms_atomic.c b/tests/kms_atomic.c
index 6375fede7179..77429b3db384 100644
--- a/tests/kms_atomic.c
+++ b/tests/kms_atomic.c
@@ -1205,6 +1205,15 @@ static void crtc_invalid_params(struct kms_atomic_crtc_state *crtc_old,
crtc_commit_atomic(&crtc, plane, req, ATOMIC_RELAX_NONE,
DRM_MODE_ATOMIC_TEST_ONLY);

+ /*
+ * TEST_ONLY cannot be combined with DRM_MODE_PAGE_FLIP_EVENT,
+ * but DRM_MODE_PAGE_FLIP_EVENT will always generate EINVAL
+ * without valid crtc, so test it here.
+ */
+ crtc_commit_atomic_err(&crtc, plane, req, ATOMIC_RELAX_NONE,
+ DRM_MODE_ATOMIC_TEST_ONLY | DRM_MODE_PAGE_FLIP_EVENT,
+ EINVAL);
+
/* Create a blob which is the wrong size to be a valid mode. */
do_or_die(drmModeCreatePropertyBlob(crtc.state->desc->fd,
crtc.mode.data,
@@ -1356,12 +1365,12 @@ static void atomic_invalid_params(struct kms_atomic_crtc_state *crtc,
/* Valid pointers, but still should copy nothing. */
do_ioctl(desc->fd, DRM_IOCTL_MODE_ATOMIC, &ioc);

- /* Nonsense flags. */
- ioc.flags = 0xdeadbeef;
+ /* Valid noop, but with event set should fail. */
+ ioc.flags = DRM_MODE_PAGE_FLIP_EVENT;
do_ioctl_err(desc->fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);

- /* Specifically forbidden combination. */
- ioc.flags = DRM_MODE_ATOMIC_TEST_ONLY | DRM_MODE_PAGE_FLIP_EVENT;
+ /* Nonsense flags. */
+ ioc.flags = 0xdeadbeef;
do_ioctl_err(desc->fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);

ioc.flags = 0;

2017-06-27 15:16:41

by Daniel Vetter

[permalink] [raw]
Subject: Re: [PATCH v2] drm/core: Fail atomic IOCTL with no CRTC state but with signaling.

On Tue, Jun 27, 2017 at 04:29:44PM +0200, Maarten Lankhorst wrote:
> Op 27-06-17 om 09:37 schreef Daniel Vetter:
> > On Mon, Jun 26, 2017 at 03:44:07PM -0400, Harry Wentland wrote:
> >> On 2017-06-20 01:57 PM, Andrey Grodzovsky wrote:
> >>> Problem : While running IGT kms_atomic_transition test suite i encountered
> >>> a hang in drmHandleEvent immediately following an atomic_commit.
> >>> After dumping the atomic state I relized that in this case there was
> >>> not even one CRTC attached to the state and only disabled
> >>> planes. This probably due to a commit which hadn't changed any property
> >>> which would require attaching crtc state. This means drmHandleEvent
> >>> will never wake up from read since without CRTC in atomic state
> >>> the event fd will not be signaled.
> >>>
> >>> Fix: Protect against this issue by failing atomic_commit early in
> >>> drm_mode_atomic_commit where such probelm can be identified.
> >>>
> >>> v2:
> >>> Fix typos and extra newlines.
> >>>
> >>> Change-Id: I3ee28ffae35fd1e8bfe553146c44da53da02e6f8
> >>> Signed-off-by: Andrey Grodzovsky <[email protected]>
> >> Reviewed-by: Harry Wentland <[email protected]>
> > Stalling on this hoping for the igt patch. Does it exist already?
> > -Daniel
> >
> >> Harry
> >>
> >>> ---
> >>> drivers/gpu/drm/drm_atomic.c | 11 ++++++++++-
> >>> 1 file changed, 10 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> >>> index a567310..48145bf 100644
> >>> --- a/drivers/gpu/drm/drm_atomic.c
> >>> +++ b/drivers/gpu/drm/drm_atomic.c
> >>> @@ -1933,7 +1933,7 @@ static int prepare_crtc_signaling(struct drm_device *dev,
> >>> {
> >>> struct drm_crtc *crtc;
> >>> struct drm_crtc_state *crtc_state;
> >>> - int i, ret;
> >>> + int i, c = 0, ret;
> >>>
> >>> if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)
> >>> return 0;
> >>> @@ -1994,8 +1994,17 @@ static int prepare_crtc_signaling(struct drm_device *dev,
> >>>
> >>> crtc_state->event->base.fence = fence;
> >>> }
> >>> +
> >>> + c++;
> >>> }
> >>>
> >>> + /*
> >>> + * Having this flag means user mode pends on event which will never
> >>> + * reach due to lack of at least one CRTC for signaling
> >>> + */
> >>> + if (c == 0 && (arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
> >>> + return -EINVAL;
> >>> +
> >>> return 0;
> >>> }
> >>>
> >>>
> Just do it, and I'll commit this to igt?

Ack on both the kernel patch and the igt patch, feel free to push them
both with:

Acked-by: Daniel Vetter <[email protected]>

If you do, please add the Testcase: line to the kernel patch.

Thanks, Daniel

>
> diff --git a/tests/kms_atomic.c b/tests/kms_atomic.c
> index 6375fede7179..77429b3db384 100644
> --- a/tests/kms_atomic.c
> +++ b/tests/kms_atomic.c
> @@ -1205,6 +1205,15 @@ static void crtc_invalid_params(struct kms_atomic_crtc_state *crtc_old,
> crtc_commit_atomic(&crtc, plane, req, ATOMIC_RELAX_NONE,
> DRM_MODE_ATOMIC_TEST_ONLY);
>
> + /*
> + * TEST_ONLY cannot be combined with DRM_MODE_PAGE_FLIP_EVENT,
> + * but DRM_MODE_PAGE_FLIP_EVENT will always generate EINVAL
> + * without valid crtc, so test it here.
> + */
> + crtc_commit_atomic_err(&crtc, plane, req, ATOMIC_RELAX_NONE,
> + DRM_MODE_ATOMIC_TEST_ONLY | DRM_MODE_PAGE_FLIP_EVENT,
> + EINVAL);
> +
> /* Create a blob which is the wrong size to be a valid mode. */
> do_or_die(drmModeCreatePropertyBlob(crtc.state->desc->fd,
> crtc.mode.data,
> @@ -1356,12 +1365,12 @@ static void atomic_invalid_params(struct kms_atomic_crtc_state *crtc,
> /* Valid pointers, but still should copy nothing. */
> do_ioctl(desc->fd, DRM_IOCTL_MODE_ATOMIC, &ioc);
>
> - /* Nonsense flags. */
> - ioc.flags = 0xdeadbeef;
> + /* Valid noop, but with event set should fail. */
> + ioc.flags = DRM_MODE_PAGE_FLIP_EVENT;
> do_ioctl_err(desc->fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
>
> - /* Specifically forbidden combination. */
> - ioc.flags = DRM_MODE_ATOMIC_TEST_ONLY | DRM_MODE_PAGE_FLIP_EVENT;
> + /* Nonsense flags. */
> + ioc.flags = 0xdeadbeef;
> do_ioctl_err(desc->fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
>
> ioc.flags = 0;
>
> _______________________________________________
> dri-devel mailing list
> [email protected]
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

2017-06-28 10:23:17

by Maarten Lankhorst

[permalink] [raw]
Subject: Re: [PATCH v2] drm/core: Fail atomic IOCTL with no CRTC state but with signaling.

Op 27-06-17 om 17:01 schreef Daniel Vetter:
> On Tue, Jun 27, 2017 at 04:29:44PM +0200, Maarten Lankhorst wrote:
>> Op 27-06-17 om 09:37 schreef Daniel Vetter:
>>> On Mon, Jun 26, 2017 at 03:44:07PM -0400, Harry Wentland wrote:
>>>> On 2017-06-20 01:57 PM, Andrey Grodzovsky wrote:
>>>>> Problem : While running IGT kms_atomic_transition test suite i encountered
>>>>> a hang in drmHandleEvent immediately following an atomic_commit.
>>>>> After dumping the atomic state I relized that in this case there was
>>>>> not even one CRTC attached to the state and only disabled
>>>>> planes. This probably due to a commit which hadn't changed any property
>>>>> which would require attaching crtc state. This means drmHandleEvent
>>>>> will never wake up from read since without CRTC in atomic state
>>>>> the event fd will not be signaled.
>>>>>
>>>>> Fix: Protect against this issue by failing atomic_commit early in
>>>>> drm_mode_atomic_commit where such probelm can be identified.
>>>>>
>>>>> v2:
>>>>> Fix typos and extra newlines.
>>>>>
>>>>> Change-Id: I3ee28ffae35fd1e8bfe553146c44da53da02e6f8
>>>>> Signed-off-by: Andrey Grodzovsky <[email protected]>
>>>> Reviewed-by: Harry Wentland <[email protected]>
>>> Stalling on this hoping for the igt patch. Does it exist already?
>>> -Daniel
>>>
>>>> Harry
>>>>
>>>>> ---
>>>>> drivers/gpu/drm/drm_atomic.c | 11 ++++++++++-
>>>>> 1 file changed, 10 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
>>>>> index a567310..48145bf 100644
>>>>> --- a/drivers/gpu/drm/drm_atomic.c
>>>>> +++ b/drivers/gpu/drm/drm_atomic.c
>>>>> @@ -1933,7 +1933,7 @@ static int prepare_crtc_signaling(struct drm_device *dev,
>>>>> {
>>>>> struct drm_crtc *crtc;
>>>>> struct drm_crtc_state *crtc_state;
>>>>> - int i, ret;
>>>>> + int i, c = 0, ret;
>>>>>
>>>>> if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)
>>>>> return 0;
>>>>> @@ -1994,8 +1994,17 @@ static int prepare_crtc_signaling(struct drm_device *dev,
>>>>>
>>>>> crtc_state->event->base.fence = fence;
>>>>> }
>>>>> +
>>>>> + c++;
>>>>> }
>>>>>
>>>>> + /*
>>>>> + * Having this flag means user mode pends on event which will never
>>>>> + * reach due to lack of at least one CRTC for signaling
>>>>> + */
>>>>> + if (c == 0 && (arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
>>>>> + return -EINVAL;
>>>>> +
>>>>> return 0;
>>>>> }
>>>>>
>>>>>
>> Just do it, and I'll commit this to igt?
> Ack on both the kernel patch and the igt patch, feel free to push them
> both with:
>
> Acked-by: Daniel Vetter <[email protected]>
>
> If you do, please add the Testcase: line to the kernel patch.
Oops, missed adding the testcase to commit message, but pushed.

I've pushed the IGT testcase as well, after fixing it up to make sure it works as intended.

~Maarten