26 Dec, 2016

2 commits

  • ktime_set(S,N) was required for the timespec storage type and is still
    useful for situations where a Seconds and Nanoseconds part of a time value
    needs to be converted. For anything where the Seconds argument is 0, this
    is pointless and can be replaced with a simple assignment.

    Signed-off-by: Thomas Gleixner
    Cc: Peter Zijlstra

    Thomas Gleixner
     
  • ktime is a union because the initial implementation stored the time in
    scalar nanoseconds on 64 bit machine and in a endianess optimized timespec
    variant for 32bit machines. The Y2038 cleanup removed the timespec variant
    and switched everything to scalar nanoseconds. The union remained, but
    become completely pointless.

    Get rid of the union and just keep ktime_t as simple typedef of type s64.

    The conversion was done with coccinelle and some manual mopping up.

    Signed-off-by: Thomas Gleixner
    Cc: Peter Zijlstra

    Thomas Gleixner
     

12 Jul, 2016

1 commit


04 Jun, 2016

1 commit

  • This patch fixes a RTC wakealarm issue, namely, the event fires during
    hibernate and is not cleared from the list, causing hwclock to block.

    The current enqueuing does not trigger an alarm if any expired timers
    already exist on the timerqueue. This can occur when a RTC wake alarm
    is used to wake a machine out of hibernate and the resumed state has
    old expired timers that have not been removed from the timer queue.
    This fix skips over any expired timers and triggers an alarm if there
    are no pending timers on the timerqueue. Note that the skipped expired
    timer will get reaped later on, so there is no need to clean it up
    immediately.

    The issue can be reproduced by putting a machine into hibernate and
    waking it with the RTC wakealarm. Running the example RTC test program
    from tools/testing/selftests/timers/rtctest.c after the hibernate will
    block indefinitely. With the fix, it no longer blocks after the
    hibernate resume.

    BugLink: http://bugs.launchpad.net/bugs/1333569

    Signed-off-by: Colin Ian King
    Signed-off-by: Alexandre Belloni

    Colin Ian King
     

30 May, 2016

1 commit


15 Mar, 2016

1 commit

  • A number of rtc devices, such as the NXP pcf2123 include a facility
    to adjust the clock in order to compensate for temperature or a
    crystal, capacitor, etc, that results in the rtc clock not running
    at exactly 32.768 kHz.

    Data sheets I have seen refer to this as a clock offset, and measure it
    in parts per million, however they often reference ppm to 2 digits of
    precision, which makes integer ppm less than ideal.

    We use parts per billion, which more than covers the precision needed
    and works nicely within 32 bits

    Signed-off-by: Joshua Clayton
    Signed-off-by: Alexandre Belloni

    Joshua Clayton
     

05 Sep, 2015

1 commit

  • IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there
    is no need to do that again from its callers. Drop it.

    gemini driver was using likely() for a failure case while the rtc driver
    is getting registered. That looks wrong and it should really be
    unlikely. But because we are killing all the unlikely() flags, lets kill
    that too.

    Signed-off-by: Viresh Kumar
    Acked-by: Hans Ulli Kroll
    Signed-off-by: Alexandre Belloni

    viresh kumar
     

25 Jun, 2015

1 commit


20 Jun, 2015

1 commit


17 Apr, 2015

1 commit

  • __rtc_read_time logs should be debug logs instead of error logs.

    For example, when the RTC clock is not set, it's not really useful
    to print a kernel error log every time someone tries to read the clock:

    ~ # hwclock -r
    [ 604.508263] rtc rtc0: read_time: fail to read
    hwclock: RTC_RD_TIME: Invalid argument

    If there's a real error, it's likely that lower level or higher level
    code will tell it anyway. Make these logs debug logs, and also print
    the error code for the read failure.

    Signed-off-by: Aaro Koskinen
    Acked-by: Alexandre Belloni
    Cc: Alessandro Zummo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Aaro Koskinen
     

03 Apr, 2015

1 commit

  • Currently the rtc_class_op's set_mmss() function takes a 32-bit
    second value (on 32-bit systems), which is problematic for dates
    past y2038.

    This patch provides a safe version named set_mmss64() using
    y2038 safe time64_t.

    After this patch, set_mmss() is deprecated and all its users
    will be fixed to use set_mmss64(), it can be removed when having
    no users.

    Signed-off-by: Xunlei Pang
    [jstultz: Add whitespace fix for checkpatch]
    Signed-off-by: John Stultz
    Acked-by: Alessandro Zummo
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/1427945681-29972-8-git-send-email-john.stultz@linaro.org
    Signed-off-by: Ingo Molnar

    Xunlei Pang
     

24 Jan, 2015

1 commit

  • Currently, interface.c uses y2038 problematic rtc_tm_to_time()
    and rtc_time_to_tm(). So replace them with their corresponding
    y2038-safe versions: rtc_tm_to_time64() and rtc_time64_to_tm().

    Cc: pang.xunlei
    Cc: Arnd Bergmann
    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Signed-off-by: Xunlei Pang
    Signed-off-by: John Stultz

    Xunlei Pang
     

11 Dec, 2014

2 commits

  • rtc_timer_do_work() only judges -ETIME failure of__rtc_set_alarm(), but
    doesn't handle other failures like -EIO, -EBUSY, etc.

    If there is a failure other than -ETIME, the next rtc_timer will stay in
    the timerqueue. Then later rtc_timers will be enqueued directly because
    they have a later expires time, so the alarm irq will never be programmed.

    When such failures happen, this patch will retry __rtc_set_alarm(), if
    still can't program the alarm time, it will remove current rtc_timer from
    timerqueue and fetch next one, thus preventing it from affecting other rtc
    timers.

    Signed-off-by: Xunlei Pang
    Cc: Alessandro Zummo
    Cc: John Stultz
    Cc: Arnd Bergmann
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Xunlei Pang
     
  • Some rtc devices always return '0' when rtc_class_ops.read_time is
    called. So if rtc_time isn't verified in callback, rtc interface cannot
    know whether rtc_time is valid.

    Check rtc_time by using 'rtc_valid_tm' in '__rtc_read_time'. And add
    the message for debugging.

    Signed-off-by: Hyogi Gim
    Cc: Alessandro Zummo
    Cc: John Stultz
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Hyogi Gim
     

09 Aug, 2014

1 commit


07 Jun, 2014

1 commit

  • In __rtc_read_alarm(), if the alarm time retrieved by
    rtc_read_alarm_internal() from the device contains invalid values (e.g.
    month=2,mday=31) and the year not set (=-1), the initialization will
    loop infinitely because the year-fixing loop expects the time being
    invalid due to leap year.

    Fix reduces the loop to the leap years and adds final validity check.

    Signed-off-by: Ales Novak
    Acked-by: Alessandro Zummo
    Reported-by: Jiri Bohac
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ales Novak
     

04 Apr, 2014

1 commit


23 Jul, 2013

1 commit

  • Current implementation of RTC interface allows for system suspend to
    occur in the following cases:
    (a) if a timer is set in the past and rtc_timer_do_work() is scheduled
    to handle it, and
    (b) if rtc_timer_do_work() is called to handle expired timers whose
    handlers implement a preemption point.

    A pending suspend request may be honoured in the above cases causing
    timer handling to be delayed until after the next resume. This is
    undesirable since timer handlers may have time-critical code to execute.

    This patch makes sure that the system stays awake until all expired
    timers are handled.

    Note that all calls to pm_stay_awake() are eventually paired with
    the single pm_relax() call in rtc_timer_do_work(), which is launched
    using schedule_work().

    Cc: Alessandro Zummo
    Cc: John Stultz
    Cc: Arve Hjonnevag
    Cc: Todd Poynor
    Signed-off-by: Zoran Markovic
    Signed-off-by: John Stultz

    Zoran Markovic
     

04 Jul, 2013

2 commits


07 Feb, 2013

1 commit

  • All in-kernel users of class_find_device() don't really need mutable
    data for match callback.

    In two places (kernel/power/suspend_test.c, drivers/scsi/osd/osd_uld.c)
    this patch changes match callbacks to use const search data.

    The const is propagated to rtc_class_open() and power_supply_get_by_name()
    parameters.

    Note that there's a dev reference leak in suspend_test.c that's not
    touched in this patch.

    Signed-off-by: Michał Mirosław
    Acked-by: Grant Likely
    Signed-off-by: Greg Kroah-Hartman

    Michał Mirosław
     

09 Aug, 2012

1 commit

  • If an RTC alarm fires just as suspend is happening, it is possible for
    suspend to complete and the alarm to be missed.

    To avoid the race, we must register the event with the PM core.

    As the event is made visible to userspace through a thread which is
    only scheduled by the interrupt, we need a pm_stay_awake/pm_relax
    pair preventing suspend from the interrupt until the thread completes
    its work.

    This makes the pm_wakeup_event() call in cmos_interrupt unnecessary as
    it provides suspend protection for all RTCs that use rtc_update_irq.

    Signed-off-by: NeilBrown
    Signed-off-by: Rafael J. Wysocki

    NeilBrown
     

16 Mar, 2012

1 commit

  • Richard Weinberger noticed that on some RTC hardware that
    doesn't support UIE mode, due to coarse granular alarms
    (like 1minute resolution), the current virtualized RTC
    support doesn't properly error out when UIE is enabled.

    Instead the current code queues an alarm for the next second,
    but it won't fire until up to a miniute later.

    This patch provides a generic way to flag this sort of hardware
    and fixes the issue on the mpc5121 where Richard noticed the
    problem.

    CC: stable@vger.kernel.org
    Reported-by: Richard Weinberger
    Tested-by: Richard Weinberger
    Signed-off-by: John Stultz

    John Stultz
     

27 Jan, 2012

3 commits

  • Currently, the RTC code does not disable the alarm in the hardware.

    This means that after a sequence such as the one below (the files are in the
    RTC sysfs), the box will boot up after 2 minutes even though we've
    asked for the alarm to be turned off.

    # echo $((`cat since_epoch`)+120) > wakealarm
    # echo 0 > wakealarm
    # poweroff

    Fix this by disabling the alarm when there are no timers to run.

    The original version of this patch was reverted. This version
    disables the irq directly instead of setting a disabled timer
    in the future.

    Cc: stable@kernel.org
    Cc: John Stultz
    Signed-off-by: Rabin Vincent
    [Merged in the second revision from Rabin]
    Signed-off-by: John Stultz

    Rabin Vincent
     
  • If the alarm time programming in the rtc is ever in the past, it won't fire,
    and any other alarm will be queued after it so they won't fire either.

    So any time that the alarm might be in the past, we need to trigger
    the irq handler to ensure the old alarm is cleared and the timer queue
    is fully in the future.

    This is done whenever the RTC clock is set.

    This is the second revision of this patch, which was earlier reverted.
    This version avoids the initialization problem, which is handled by
    a different patch.

    Tested-by: Sander Eikelenboom
    Signed-off-by: NeilBrown
    [Remove problematic initialization change, update commit log, also
    catch set_mmss case -jstultz]
    Signed-off-by: John Stultz

    NeilBrown
     
  • In some cases at boot up, the RTC alarm may be set in the past,
    but still have the enabled flag on. This was causing problems,
    because we would then enqueue the alarm into the timerqueue,
    but it would never fire. This would clog up the timerqueue
    and keep other alarms from working.

    The fix is to check the alarm against the current rtc time at
    boot and avoid enqueueing the alarm if it is in the past.

    Reported-by: NeilBrown
    Tested-by: NeilBrown
    Tested-by: Sander Eikelenboom
    Signed-off-by: John Stultz

    John Stultz
     

11 Jan, 2012

1 commit

  • Commit f44f7f96a20a ("RTC: Initialize kernel state from RTC") introduced a
    potential infinite loop. If an alarm time contains a wildcard month and
    an invalid day (> 31), or a wildcard year and an invalid month (>= 12),
    the loop searching for the next matching date will never terminate. Treat
    the invalid values as wildcards.

    Fixes ,

    Reported-by: leo weppelman
    Reported-by: "P. van Gaans"
    Signed-off-by: Ben Hutchings
    Signed-off-by: Jonathan Nieder
    Cc: Mark Brown
    Cc: Marcelo Roberto Jimenez
    Cc: Thomas Gleixner
    Cc: John Stultz
    Acked-by: Alessandro Zummo
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ben Hutchings
     

04 Jan, 2012

2 commits

  • This reverts commit 93b2ec0128c431148b216b8f7337c1a52131ef03.

    The call to "schedule_work()" in rtc_initialize_alarm() happens too
    early, and can cause oopses at bootup

    Neil Brown explains why we do it:

    "If you set an alarm in the future, then shutdown and boot again after
    that time, then you will end up with a timer_queue node which is in
    the past.

    When this happens the queue gets stuck. That entry-in-the-past won't
    get removed until and interrupt happens and an interrupt won't happen
    because the RTC only triggers an interrupt when the alarm is "now".

    So you'll find that e.g. "hwclock" will always tell you that
    'select' timed out.

    So we force the interrupt work to happen at the start just in case."

    and has a patch that convert it to do things in-process rather than with
    the worker thread, but right now it's too late to play around with this,
    so we just revert the patch that caused problems for now.

    Reported-by: Sander Eikelenboom
    Requested-by: Konrad Rzeszutek Wilk
    Requested-by: John Stultz
    Cc: Neil Brown
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     
  • This reverts commit c0afabd3d553c521e003779c127143ffde55a16f.

    It causes failures on Toshiba laptops - instead of disabling the alarm,
    it actually seems to enable it on the affected laptops, resulting in
    (for example) the laptop powering on automatically five minutes after
    shutdown.

    There's a patch for it that appears to work for at least some people,
    but it's too late to play around with this, so revert for now and try
    again in the next merge window.

    See for example

    http://bugs.debian.org/652869

    Reported-and-bisected-by: Andreas Friedrich (Toshiba Tecra)
    Reported-by: Antonio-M. Corbi Bellot (Toshiba Portege R500)
    Reported-by: Marco Santos (Toshiba Portege Z830)
    Reported-by: Christophe Vu-Brugier (Toshiba Portege R830)
    Cc: Jonathan Nieder
    Requested-by: John Stultz
    Cc: stable@kernel.org # for the versions that applied this
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     

14 Dec, 2011

1 commit

  • If the alarm time programming in the rtc is ever in the past, it won't fire,
    and any other alarm will be queued after it so they won't fire either.

    So any time that the alarm might be in the past, we need to trigger
    the irq handler to ensure the old alarm is cleared and the timer queue
    is fully in the future.

    This can happen:
    - when we first initialise the alarm
    - when we set the time in the rtc.

    so follow both of these by scheduling the timer work function.

    CC: stable@kernel.org
    Signed-off-by: NeilBrown
    [Also catch set_mmss case -jstultz]
    Signed-off-by: John Stultz

    NeilBrown
     

06 Dec, 2011

1 commit


23 Nov, 2011

1 commit

  • Currently, the RTC code does not disable the alarm in the hardware.

    This means that after a sequence such as the one below (the files are in the
    RTC sysfs), the box will boot up after 2 minutes even though we've
    asked for the alarm to be turned off.

    # echo $((`cat since_epoch`)+120) > wakealarm
    # echo 0 > wakealarm
    # poweroff

    Fix this by disabling the alarm when there are no timers to run.

    Cc: stable@kernel.org
    Cc: John Stultz
    Signed-off-by: Rabin Vincent
    Signed-off-by: John Stultz

    Rabin Vincent
     

01 Nov, 2011

1 commit


27 Jul, 2011

6 commits

  • Ben reported a lockup related to rtc. The lockup happens due to:

    CPU0 CPU1

    rtc_irq_set_state() __run_hrtimer()
    spin_lock_irqsave(&rtc->irq_task_lock) rtc_handle_legacy_irq();
    spin_lock(&rtc->irq_task_lock);
    hrtimer_cancel()
    while (callback_running);

    So the running callback never finishes as it's blocked on
    rtc->irq_task_lock.

    Use hrtimer_try_to_cancel() instead and drop rtc->irq_task_lock while
    waiting for the callback. Fix this for both rtc_irq_set_state() and
    rtc_irq_set_freq().

    Signed-off-by: Thomas Gleixner
    Reported-by: Ben Greear
    Cc: John Stultz
    Cc: Ingo Molnar
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Thomas Gleixner
     
  • Due to the hrtimer self rearming mode a user can DoS the machine simply
    because it's starved by hrtimer events.

    The RTC hrtimer is self rearming. We really need to limit the frequency
    to something sensible.

    Signed-off-by: Thomas Gleixner
    Cc: John Stultz
    Cc: Ingo Molnar
    Cc: Ben Greear
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Thomas Gleixner
     
  • The code checks the correctness of the parameters, but unconditionally
    arms/disarms the hrtimer.

    The result is that a random task might arm/disarm rtc timer and surprise
    the real owner by either generating events or by stopping them.

    Signed-off-by: Thomas Gleixner
    Cc: John Stultz
    Cc: Ingo Molnar
    Cc: Ben Greear
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Thomas Gleixner
     
  • The RTC pie hrtimer is self rearming. We really need to limit the
    frequency to something sensible. Thus limit it to the 8192Hz max
    value from the rtc man documentation

    Cc: Willy Tarreau
    Cc: stable@kernel.org
    Signed-off-by: Thomas Gleixner
    [jstultz: slightly reworked to use RTC_MAX_FREQ value]
    Signed-off-by: John Stultz

    Thomas Gleixner
     
  • Ben reported a lockup related to rtc. The lockup happens due to:

    CPU0 CPU1

    rtc_irq_set_state() __run_hrtimer()
    spin_lock_irqsave(&rtc->irq_task_lock) rtc_handle_legacy_irq();
    spin_lock(&rtc->irq_task_lock);
    hrtimer_cancel()
    while (callback_running);

    So the running callback never finishes as it's blocked on
    rtc->irq_task_lock.

    Use hrtimer_try_to_cancel() instead and drop rtc->irq_task_lock while
    waiting for the callback. Fix this for both rtc_irq_set_state() and
    rtc_irq_set_freq().

    Cc: stable@kernel.org
    Reported-by: Ben Greear
    Signed-off-by: Thomas Gleixner
    Signed-off-by: John Stultz

    Thomas Gleixner
     
  • In rtc_irq_set_state, the code checks the correctness of the parameters,
    but then goes on to unconditionally arms/disarms the hrtimer. Thus a
    random task might arm/disarm rtc timer and surprise the real owner by
    either generating events or by stopping them.

    Cc: stable@kernel.org
    Signed-off-by: Thomas Gleixner
    Signed-off-by: John Stultz

    Thomas Gleixner
     

02 Jun, 2011

1 commit