2013-10-14 21:33:29

by KOSAKI Motohiro

[permalink] [raw]
Subject: [PATCH] alarmtimer: return EINVAL instead of ENOTSUPP if rtcdev doesn't exist

From: KOSAKI Motohiro <[email protected]>

Fedora Ruby maintainer reported latest Ruby doesn't work on Fedora Rawhide
on ARM. (http://bugs.ruby-lang.org/issues/9008)

Because of, commit 1c6b39ad3f (alarmtimers: Return -ENOTSUPP if no
RTC device is present) intruduced to return ENOTSUPP when
clock_get{time,res} can't find a RTC device. However it is incorrect.

Posix and Linux man pages agree that clock_gettime and clock_getres
should return EINVAL if clk_id argument is invalid. This is significant
different from timer_create API.

This patch fixes it.

Reported-by: Vit Ondruch <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: John Stultz <[email protected]>
Signed-off-by: KOSAKI Motohiro <[email protected]>
---
kernel/time/alarmtimer.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index eec50fc..88c9c65 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -490,7 +490,7 @@ static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp)
clockid_t baseid = alarm_bases[clock2alarm(which_clock)].base_clockid;

if (!alarmtimer_get_rtcdev())
- return -ENOTSUPP;
+ return -EINVAL;

return hrtimer_get_res(baseid, tp);
}
@@ -507,7 +507,7 @@ static int alarm_clock_get(clockid_t which_clock, struct timespec *tp)
struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)];

if (!alarmtimer_get_rtcdev())
- return -ENOTSUPP;
+ return -EINVAL;

*tp = ktime_to_timespec(base->gettime());
return 0;
--
1.7.1


2013-10-17 17:05:17

by John Stultz

[permalink] [raw]
Subject: Re: [PATCH] alarmtimer: return EINVAL instead of ENOTSUPP if rtcdev doesn't exist

On 10/14/2013 02:33 PM, [email protected] wrote:
> From: KOSAKI Motohiro <[email protected]>
>
> Fedora Ruby maintainer reported latest Ruby doesn't work on Fedora Rawhide
> on ARM. (http://bugs.ruby-lang.org/issues/9008)
>
> Because of, commit 1c6b39ad3f (alarmtimers: Return -ENOTSUPP if no
> RTC device is present) intruduced to return ENOTSUPP when
> clock_get{time,res} can't find a RTC device. However it is incorrect.
>
> Posix and Linux man pages agree that clock_gettime and clock_getres
> should return EINVAL if clk_id argument is invalid. This is significant
> different from timer_create API.
>
> This patch fixes it.

Hrm... So I feel like there is a difference here. The clockid for
CLOCK_BOOTTIME_ALARM and CLOCK_REALTIME_ALARM are both valid.

Its just that they're not supported on this specific hardware because it
apparently lacks a RTC that has told the system it can be used as a
wakeup device (Its actually quite likely on the hardware that the RTC
can be a wakeup device, but that the driver is probably setting the
wakeup flag after the RTC registered - so there is probably a driver bug
here too).

So I feel like in this case EINVAL isn't quite right. I'll admit it is
somewhat new behavior, because we haven't had any clockids before that
were dependent on the particular hardware, they either existed in a
kernel verison or didn't.

Would updating the manpage be a better route?

thanks
-john

2013-10-18 01:12:09

by KOSAKI Motohiro

[permalink] [raw]
Subject: Re: [PATCH] alarmtimer: return EINVAL instead of ENOTSUPP if rtcdev doesn't exist

(10/17/13 1:05 PM), John Stultz wrote:
> On 10/14/2013 02:33 PM, [email protected] wrote:
>> From: KOSAKI Motohiro <[email protected]>
>>
>> Fedora Ruby maintainer reported latest Ruby doesn't work on Fedora Rawhide
>> on ARM. (http://bugs.ruby-lang.org/issues/9008)
>>
>> Because of, commit 1c6b39ad3f (alarmtimers: Return -ENOTSUPP if no
>> RTC device is present) intruduced to return ENOTSUPP when
>> clock_get{time,res} can't find a RTC device. However it is incorrect.
>>
>> Posix and Linux man pages agree that clock_gettime and clock_getres
>> should return EINVAL if clk_id argument is invalid. This is significant
>> different from timer_create API.
>>
>> This patch fixes it.
>
> Hrm... So I feel like there is a difference here. The clockid for
> CLOCK_BOOTTIME_ALARM and CLOCK_REALTIME_ALARM are both valid.
>
> Its just that they're not supported on this specific hardware because it
> apparently lacks a RTC that has told the system it can be used as a
> wakeup device (Its actually quite likely on the hardware that the RTC
> can be a wakeup device, but that the driver is probably setting the
> wakeup flag after the RTC registered - so there is probably a driver bug
> here too).
>
> So I feel like in this case EINVAL isn't quite right. I'll admit it is
> somewhat new behavior, because we haven't had any clockids before that
> were dependent on the particular hardware, they either existed in a
> kernel verison or didn't.
>
> Would updating the manpage be a better route?

Nope.

ENOTSUPP is not exported to userland. ENOTSUP (single P) and EOPNOTSUP is
valid errno (and they are same on linux), but ENOTSUPP is a kernel internal specific.

Moreover, I completely disagree your position. Both CLOCK_REALTIME_ALARM unsupported
kernel and ARM which doesn't support RTC should use the same error because application
need the same fallback.


2013-10-18 22:39:09

by John Stultz

[permalink] [raw]
Subject: Re: [PATCH] alarmtimer: return EINVAL instead of ENOTSUPP if rtcdev doesn't exist

On 10/17/2013 06:12 PM, KOSAKI Motohiro wrote:
> (10/17/13 1:05 PM), John Stultz wrote:
>> On 10/14/2013 02:33 PM, [email protected] wrote:
>>> From: KOSAKI Motohiro <[email protected]>
>>>
>>> Fedora Ruby maintainer reported latest Ruby doesn't work on Fedora
>>> Rawhide
>>> on ARM. (http://bugs.ruby-lang.org/issues/9008)
>>>
>>> Because of, commit 1c6b39ad3f (alarmtimers: Return -ENOTSUPP if no
>>> RTC device is present) intruduced to return ENOTSUPP when
>>> clock_get{time,res} can't find a RTC device. However it is incorrect.
>>>
>>> Posix and Linux man pages agree that clock_gettime and clock_getres
>>> should return EINVAL if clk_id argument is invalid. This is significant
>>> different from timer_create API.
>>>
>>> This patch fixes it.
>>
>> Hrm... So I feel like there is a difference here. The clockid for
>> CLOCK_BOOTTIME_ALARM and CLOCK_REALTIME_ALARM are both valid.
>>
>> Its just that they're not supported on this specific hardware because it
>> apparently lacks a RTC that has told the system it can be used as a
>> wakeup device (Its actually quite likely on the hardware that the RTC
>> can be a wakeup device, but that the driver is probably setting the
>> wakeup flag after the RTC registered - so there is probably a driver bug
>> here too).
>>
>> So I feel like in this case EINVAL isn't quite right. I'll admit it is
>> somewhat new behavior, because we haven't had any clockids before that
>> were dependent on the particular hardware, they either existed in a
>> kernel verison or didn't.
>>
>> Would updating the manpage be a better route?
>
> Nope.
>
> ENOTSUPP is not exported to userland. ENOTSUP (single P) and EOPNOTSUP is
> valid errno (and they are same on linux), but ENOTSUPP is a kernel
> internal specific.
>
> Moreover, I completely disagree your position. Both
> CLOCK_REALTIME_ALARM unsupported
> kernel and ARM which doesn't support RTC should use the same error
> because application
> need the same fallback.

Ok. You're right. The technicality that the clockid is valid but
unsupported isn't really useful to the applications, since the effect is
the same.

What is the urgency on this? As the issue has been around since 3.0, is
it ok if it gets queued for 3.13 and marked for stable, or does it need
to land in 3.12?

thanks
-john

2013-10-18 23:12:07

by KOSAKI Motohiro

[permalink] [raw]
Subject: Re: [PATCH] alarmtimer: return EINVAL instead of ENOTSUPP if rtcdev doesn't exist

On 10/18/2013 6:39 PM, John Stultz wrote:
> On 10/17/2013 06:12 PM, KOSAKI Motohiro wrote:
>> (10/17/13 1:05 PM), John Stultz wrote:
>>> On 10/14/2013 02:33 PM, [email protected] wrote:
>>>> From: KOSAKI Motohiro <[email protected]>
>>>>
>>>> Fedora Ruby maintainer reported latest Ruby doesn't work on Fedora
>>>> Rawhide
>>>> on ARM. (http://bugs.ruby-lang.org/issues/9008)
>>>>
>>>> Because of, commit 1c6b39ad3f (alarmtimers: Return -ENOTSUPP if no
>>>> RTC device is present) intruduced to return ENOTSUPP when
>>>> clock_get{time,res} can't find a RTC device. However it is incorrect.
>>>>
>>>> Posix and Linux man pages agree that clock_gettime and clock_getres
>>>> should return EINVAL if clk_id argument is invalid. This is significant
>>>> different from timer_create API.
>>>>
>>>> This patch fixes it.
>>>
>>> Hrm... So I feel like there is a difference here. The clockid for
>>> CLOCK_BOOTTIME_ALARM and CLOCK_REALTIME_ALARM are both valid.
>>>
>>> Its just that they're not supported on this specific hardware because it
>>> apparently lacks a RTC that has told the system it can be used as a
>>> wakeup device (Its actually quite likely on the hardware that the RTC
>>> can be a wakeup device, but that the driver is probably setting the
>>> wakeup flag after the RTC registered - so there is probably a driver bug
>>> here too).
>>>
>>> So I feel like in this case EINVAL isn't quite right. I'll admit it is
>>> somewhat new behavior, because we haven't had any clockids before that
>>> were dependent on the particular hardware, they either existed in a
>>> kernel verison or didn't.
>>>
>>> Would updating the manpage be a better route?
>>
>> Nope.
>>
>> ENOTSUPP is not exported to userland. ENOTSUP (single P) and EOPNOTSUP is
>> valid errno (and they are same on linux), but ENOTSUPP is a kernel
>> internal specific.
>>
>> Moreover, I completely disagree your position. Both
>> CLOCK_REALTIME_ALARM unsupported
>> kernel and ARM which doesn't support RTC should use the same error
>> because application
>> need the same fallback.
>
> Ok. You're right. The technicality that the clockid is valid but
> unsupported isn't really useful to the applications, since the effect is
> the same.
>
> What is the urgency on this? As the issue has been around since 3.0, is
> it ok if it gets queued for 3.13 and marked for stable, or does it need
> to land in 3.12?

3.13 is OK to me.



2013-10-18 23:29:28

by John Stultz

[permalink] [raw]
Subject: Re: [PATCH] alarmtimer: return EINVAL instead of ENOTSUPP if rtcdev doesn't exist

On 10/18/2013 04:12 PM, KOSAKI Motohiro wrote:
> On 10/18/2013 6:39 PM, John Stultz wrote:
>> On 10/17/2013 06:12 PM, KOSAKI Motohiro wrote:
>>> (10/17/13 1:05 PM), John Stultz wrote:
>>>> On 10/14/2013 02:33 PM, [email protected] wrote:
>>>>> From: KOSAKI Motohiro <[email protected]>
>>>>>
>>>>> Fedora Ruby maintainer reported latest Ruby doesn't work on Fedora
>>>>> Rawhide
>>>>> on ARM. (http://bugs.ruby-lang.org/issues/9008)
>>>>>
>>>>> Because of, commit 1c6b39ad3f (alarmtimers: Return -ENOTSUPP if no
>>>>> RTC device is present) intruduced to return ENOTSUPP when
>>>>> clock_get{time,res} can't find a RTC device. However it is incorrect.
>>>>>
>>>>> Posix and Linux man pages agree that clock_gettime and clock_getres
>>>>> should return EINVAL if clk_id argument is invalid. This is significant
>>>>> different from timer_create API.
>>>>>
>>>>> This patch fixes it.
>>>> Hrm... So I feel like there is a difference here. The clockid for
>>>> CLOCK_BOOTTIME_ALARM and CLOCK_REALTIME_ALARM are both valid.
>>>>
>>>> Its just that they're not supported on this specific hardware because it
>>>> apparently lacks a RTC that has told the system it can be used as a
>>>> wakeup device (Its actually quite likely on the hardware that the RTC
>>>> can be a wakeup device, but that the driver is probably setting the
>>>> wakeup flag after the RTC registered - so there is probably a driver bug
>>>> here too).
>>>>
>>>> So I feel like in this case EINVAL isn't quite right. I'll admit it is
>>>> somewhat new behavior, because we haven't had any clockids before that
>>>> were dependent on the particular hardware, they either existed in a
>>>> kernel verison or didn't.
>>>>
>>>> Would updating the manpage be a better route?
>>> Nope.
>>>
>>> ENOTSUPP is not exported to userland. ENOTSUP (single P) and EOPNOTSUP is
>>> valid errno (and they are same on linux), but ENOTSUPP is a kernel
>>> internal specific.
>>>
>>> Moreover, I completely disagree your position. Both
>>> CLOCK_REALTIME_ALARM unsupported
>>> kernel and ARM which doesn't support RTC should use the same error
>>> because application
>>> need the same fallback.
>> Ok. You're right. The technicality that the clockid is valid but
>> unsupported isn't really useful to the applications, since the effect is
>> the same.
>>
>> What is the urgency on this? As the issue has been around since 3.0, is
>> it ok if it gets queued for 3.13 and marked for stable, or does it need
>> to land in 3.12?
> 3.13 is OK to me.

Ok. Applied to my 3.13 queue.

thanks
-john