lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <12EF70CDEA59BA47AD9EC69F20130B3401AD2ECA@PGSMSX103.gar.corp.intel.com>
Date:	Mon, 9 Nov 2015 02:26:16 +0000
From:	"Lee, Zhuo-hao" <zhuo-hao.lee@...el.com>
To:	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	"Thomas Gleixner" <tglx@...utronix.de>
CC:	"zhuohao.lee82@...il.com" <zhuohao.lee82@...il.com>
Subject: RE: [PATCH v2] alarmtimer: fix unexpected rtc interrupt when system
 resume from S3

Hi tglx & all,

I wrote a simple program which can always hit this problem.
Please use gcc to compile the following code and then "./a.out 10000 1" and watch the /proc/interrupts, 
and you will see that the RTC interrupt will come unexpectedly after system resumed.
This abnormal interrupt should be removed. I tried on the latest linux kernel, 
the bug still exists. So, could you please help to review this patch? Or give me some feedback?


#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/timerfd.h>
#include <time.h>
#include <stdlib.h>
#include <stdint.h>

#define handle_error(msg) \
            do { perror(msg); exit(EXIT_FAILURE); } while (0)

int main(int argc, char *argv[])
{
    struct itimerspec new_value;
    int fd, sec, enable_suspend;
    struct timespec now;
    uint64_t exp;
    ssize_t s;
    pid_t pid;

    if (argc != 3) {
        fprintf(stderr, "%s secs enable_suspend\n",argv[0]);
        exit(EXIT_FAILURE);
    }

    sec = atoi(argv[1]);
    enable_suspend = atoi(argv[2]);

    if (clock_gettime(CLOCK_REALTIME, &now) == -1)
        handle_error("clock_gettime");

    /* Create a CLOCK_REALTIME absolute timer with initial
       expiration and interval as specified in command line */

    new_value.it_value.tv_sec = now.tv_sec + sec;
    new_value.it_value.tv_nsec = now.tv_nsec;
    new_value.it_interval.tv_sec = 0;
    new_value.it_interval.tv_nsec = 0;

    fd = timerfd_create(CLOCK_REALTIME_ALARM, 0);
    if (fd == -1)
        handle_error("timerfd_create");

    if (timerfd_settime(fd, TFD_TIMER_ABSTIME, &new_value, NULL) == -1)
        handle_error("timerfd_settime");

    system("cat /proc/driver/rtc | grep rtc_time");
    system("cat /proc/interrupts | grep -E 'CPU0|rtc0'");
    printf("\n\ntimer started: wait %d seconds\n\n", sec);
    pid = fork();
    if (pid == -1) {
        fprintf(stderr, "fork failed\n");
        exit(EXIT_FAILURE);
    } else if (pid == 0) {
        if(enable_suspend){
            sleep(5);
/* for chromeOS */
 //           system("echo 0 > /sys/class/rtc/rtc0/wakealarm");
//            system("echo +10 > /sys/class/rtc/rtc0/wakealarm");
//            system("powerd_dbus_suspend"); 

/* for Ubuntu */
            system("sudo pm-suspend"); 
        }
        exit(EXIT_SUCCESS);
    } else {
        s = read(fd, &exp, sizeof(uint64_t));
        if (s != sizeof(uint64_t))
            handle_error("read");

        system("cat /proc/driver/rtc |grep rtc_time");
        system("cat /proc/interrupts | grep -E 'CPU0|rtc0'");
    
        exit(EXIT_SUCCESS);
    }
}


Thanks
Lee, Zhuo-hao

-----Original Message-----
From: Lee, Zhuo-hao 
Sent: Thursday, November 5, 2015 1:50 PM
To: linux-kernel@...r.kernel.org
Cc: Thomas Gleixner; zhuohao.lee82@...il.com; Lee, Zhuo-hao
Subject: [PATCH v2] alarmtimer: fix unexpected rtc interrupt when system resume from S3

From: zhuo-hao <zhuo-hao.lee@...el.com>

Before the system go to suspend (S3), if user create a timer with clockid CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARM and set a "large" timeout value to this timer. The function alarmtimer_suspend will be called to setup a timeout value to RTC timer to avoid the system sleep over time. However, if the system wakeup early than RTC timeout, the RTC timer will not be cleared.
And this will cause the hpet_rtc_interrupt come unexpectedly until the RTC timeout. To fix this problem, just adding alarmtimer_resume to cancel the RTC timer.

Signed-off-by: Zhuo-hao Lee <zhuo-hao.lee@...el.com>
---
 kernel/time/alarmtimer.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index 7fbba63..e840ed8 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -271,11 +271,27 @@ static int alarmtimer_suspend(struct device *dev)
 		__pm_wakeup_event(ws, MSEC_PER_SEC);
 	return ret;
 }
+
+static int alarmtimer_resume(struct device *dev) {
+	struct rtc_device *rtc;
+
+	rtc = alarmtimer_get_rtcdev();
+	if (rtc)
+		rtc_timer_cancel(rtc, &rtctimer);
+	return 0;
+}
+
 #else
 static int alarmtimer_suspend(struct device *dev)  {
 	return 0;
 }
+
+static int alarmtimer_resume(struct device *dev) {
+	return 0;
+}
 #endif
 
 static void alarmtimer_freezerset(ktime_t absexp, enum alarmtimer_type type) @@ -800,6 +816,7 @@ out:
 /* Suspend hook structures */
 static const struct dev_pm_ops alarmtimer_pm_ops = {
 	.suspend = alarmtimer_suspend,
+	.resume = alarmtimer_resume,
 };
 
 static struct platform_driver alarmtimer_driver = {
--
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ