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>] [day] [month] [year] [list]
Message-ID: <20251112061532.2867859-1-zhengxinyu6@huawei.com>
Date: Wed, 12 Nov 2025 06:15:32 +0000
From: Xinyu Zheng <zhengxinyu6@...wei.com>
To: Shuah Khan <shuah@...nel.org>
CC: Moon Hee Lee <moonhee.lee.ca@...il.com>, <yifei.l.liu@...cle.com>,
	<zhujun2@...s.chinamobile.com>, <linux-kselftest@...r.kernel.org>,
	<linux-kernel@...r.kernel.org>, <zouyipeng@...wei.com>,
	<zhengxinyu6@...wei.com>
Subject: [PATCH] selftests: breakpoints: check RTC wakeup alarm support before test

If RTC wakeup alarm feature is unsupported, this testcase may cause
infinite suspend if there is no other wakeup source. To solve this
problem, set wakeup alarm up before we trigger suspend. In this case,
we can test if RTC support RTC_FEATURE_ALARM and efi_set_alarm function.

Signed-off-by: Xinyu Zheng <zhengxinyu6@...wei.com>
---
 .../breakpoints/step_after_suspend_test.c     | 23 +++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/tools/testing/selftests/breakpoints/step_after_suspend_test.c b/tools/testing/selftests/breakpoints/step_after_suspend_test.c
index 8d233ac95696..e738af896ce1 100644
--- a/tools/testing/selftests/breakpoints/step_after_suspend_test.c
+++ b/tools/testing/selftests/breakpoints/step_after_suspend_test.c
@@ -13,6 +13,8 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <linux/rtc.h>
+#include <sys/ioctl.h>
 #include <sys/ptrace.h>
 #include <sys/stat.h>
 #include <sys/timerfd.h>
@@ -159,10 +161,30 @@ void suspend(void)
 	int count_before;
 	int count_after;
 	struct itimerspec spec = {};
+	char *rtc_file = "/dev/rtc0";
+	int rtc_fd;
+	struct rtc_wkalrm alarm = { 0 };
+	time_t secs;
 
 	if (getuid() != 0)
 		ksft_exit_skip("Please run the test as root - Exiting.\n");
 
+	rtc_fd = open(rtc_file, O_RDONLY);
+	if (rtc_fd < 0)
+		ksft_exit_fail_msg("open rtc0 failed\n");
+
+	err = ioctl(rtc_fd, RTC_RD_TIME, &alarm.time);
+	if (err < 0)
+		ksft_exit_fail_msg("get rtc time failed\n");
+
+	secs = timegm((struct tm *)&alarm.time) + 3;
+	gmtime_r(&secs, (struct tm *)&alarm.time);
+	alarm.enabled = 1;
+
+	err = ioctl(rtc_fd, RTC_WKALM_SET, &alarm);
+	if (err < 0)
+		ksft_exit_fail_msg("set wake alarm test failed, errno %d\n", errno);
+
 	timerfd = timerfd_create(CLOCK_BOOTTIME_ALARM, 0);
 	if (timerfd < 0)
 		ksft_exit_fail_msg("timerfd_create() failed\n");
@@ -180,6 +202,7 @@ void suspend(void)
 	if (count_after <= count_before)
 		ksft_exit_fail_msg("Failed to enter Suspend state\n");
 
+	close(rtc_fd);
 	close(timerfd);
 }
 
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ