Skip to contentSkip to conversation

vdso: Define NSEC_PER_SEC as 64-bit to prevent overflow

PATCH In review Wake Liu 5 participants 11 messages Aug 5, 2025 – Jan 7

Subsystems (4)
lore
Share & tools
lore

Wake Liu

author
#0 lore raw

PATCH 1/1 vdso: Define NSEC_PER_SEC as 64-bit to prevent overflow

The constant NSEC_PER_SEC (1,000,000,000) is defined as a long literal. On 32-bit systems like arm32, where long is 32 bits, this value can overflow when used in 64-bit calculations.

This can lead to incorrect time calculations within the VDSO.

To fix this, define NSEC_PER_SEC as a long long literal (1000000000LL), ensuring it is treated as a 64-bit value on all architectures and preventing potential overflows.

---
 include/vdso/time64.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/vdso/time64.h +1 -1
index b40cfa2aa33c..07641b27d139 100644
@@ -8,7 +8,7 @@
 #define NSEC_PER_USEC	1000L
 #define NSEC_PER_MSEC	1000000L
 #define USEC_PER_SEC	1000000L
-#define NSEC_PER_SEC	1000000000L
+#define NSEC_PER_SEC	1000000000LL
 #define PSEC_PER_SEC	1000000000000LL
 #define FSEC_PER_SEC	1000000000000000LL
 
Signature · 1 line
2.50.1.565.gc32cd1483b-goog
#1 lore raw

On Wed, Aug 06 2025 at 00:21, Wake Liu wrote:

Why are you sending the same patch twice within a minute?

#2 lore raw
In reply to Wake Liu
Quoted 3 lines · Wake Liu

The constant NSEC_PER_SEC (1,000,000,000) is defined as a long literal. On 32-bit systems like arm32, where long is 32 bits, this value can overflow when used in 64-bit calculations.

How so? Where is the overflow exactly?

The only usage of NSEC_PER_SEC in the VDSO is:

# git grep NSEC_PER_SEC lib/vdso/
lib/vdso/gettimeofday.c:        ts->tv_sec = sec + __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns);

and __iter_div_u64_rem() is an inline:

static __always_inline u32
__iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder)

So how exactly is this causing an overflow?

Also by your description this would be a problem throughout the kernel.

Thanks,

tglx

author
#3 lore raw

Hi Thomas,

Here's the command I used in android.

```
/data/nativetest/vts_linux_kselftest_arm_32/set-timer-lat
```
And the strace message.
```
Setting timers for every 1 seconds
CLOCK_REALTIME         ABSTIME PERIODIC timer fired early:       1 : [FAILED]
CLOCK_REALTIME         ABSTIME PERIODIC max latency:     747886 ns : [OK]
CLOCK_REALTIME         RELTIME PERIODIC timer fired early:       0 : [OK]
CLOCK_REALTIME         RELTIME PERIODIC max latency: 4296109428 ns : [FAILED]
CLOCK_REALTIME         ABSTIME ONE-SHOT timer fired early:       0 : [OK]
CLOCK_REALTIME         ABSTIME ONE-SHOT max latency:     715292 ns : [OK]
CLOCK_REALTIME         ABSTIME ONE-SHOT count:                   1 : [OK]
CLOCK_REALTIME         RELTIME ONE-SHOT timer fired early:       0 : [OK]
CLOCK_REALTIME         RELTIME ONE-SHOT max latency:     628703 ns : [OK]
CLOCK_REALTIME         RELTIME ONE-SHOT count:                   1 : [OK]
CLOCK_MONOTONIC        ABSTIME PERIODIC timer fired early:       1 : [FAILED]
CLOCK_MONOTONIC        ABSTIME PERIODIC max latency:     738160 ns : [OK]
CLOCK_MONOTONIC        RELTIME PERIODIC timer fired early:       1 : [FAILED]
CLOCK_MONOTONIC        RELTIME PERIODIC max latency:     708172 ns : [OK]
CLOCK_MONOTONIC        ABSTIME ONE-SHOT timer fired early:       0 : [OK]
CLOCK_MONOTONIC        ABSTIME ONE-SHOT max latency:     586385 ns : [OK]
CLOCK_MONOTONIC        ABSTIME ONE-SHOT count:                   1 : [OK]
CLOCK_MONOTONIC        RELTIME ONE-SHOT timer fired early:       0 : [OK]
CLOCK_MONOTONIC        RELTIME ONE-SHOT max latency:     818237 ns : [OK]
CLOCK_MONOTONIC        RELTIME ONE-SHOT count:                   1 : [OK]
CLOCK_BOOTTIME         ABSTIME PERIODIC timer fired early:       1 : [FAILED]
CLOCK_BOOTTIME         ABSTIME PERIODIC max latency:     795249 ns : [OK]
CLOCK_BOOTTIME         RELTIME PERIODIC timer fired early:       0 : [OK]
CLOCK_BOOTTIME         RELTIME PERIODIC max latency: 4295613660 ns : [FAILED]
CLOCK_BOOTTIME         ABSTIME ONE-SHOT timer fired early:       0 : [OK]
CLOCK_BOOTTIME         ABSTIME ONE-SHOT max latency:     978516 ns : [OK]
CLOCK_BOOTTIME         ABSTIME ONE-SHOT count:                   1 : [OK]
CLOCK_BOOTTIME         RELTIME ONE-SHOT timer fired early:       0 : [OK]
CLOCK_BOOTTIME         RELTIME ONE-SHOT max latency:     628948 ns : [OK]
CLOCK_BOOTTIME         RELTIME ONE-SHOT count:                   1 : [OK]
CLOCK_REALTIME_ALARM   ABSTIME PERIODIC timer fired early:       1 : [FAILED]
CLOCK_REALTIME_ALARM   ABSTIME PERIODIC max latency:    1511436 ns : [OK]
CLOCK_REALTIME_ALARM   RELTIME PERIODIC timer fired early:       1 : [FAILED]
CLOCK_REALTIME_ALARM   RELTIME PERIODIC max latency:     758913 ns : [OK]
CLOCK_REALTIME_ALARM   ABSTIME ONE-SHOT timer fired early:       0 : [OK]
CLOCK_REALTIME_ALARM   ABSTIME ONE-SHOT max latency:     610881 ns : [OK]
CLOCK_REALTIME_ALARM   ABSTIME ONE-SHOT count:                   1 : [OK]
CLOCK_REALTIME_ALARM   RELTIME ONE-SHOT timer fired early:       0 : [OK]
CLOCK_REALTIME_ALARM   RELTIME ONE-SHOT max latency:     633708 ns : [OK]
CLOCK_REALTIME_ALARM   RELTIME ONE-SHOT count:                   1 : [OK]
CLOCK_BOOTTIME_ALARM   ABSTIME PERIODIC timer fired early:       0 : [OK]
CLOCK_BOOTTIME_ALARM   ABSTIME PERIODIC max latency: 4295683321 ns : [FAILED]
CLOCK_BOOTTIME_ALARM   RELTIME PERIODIC timer fired early:       0 : [OK]
CLOCK_BOOTTIME_ALARM   RELTIME PERIODIC max latency:     839520 ns : [OK]
CLOCK_BOOTTIME_ALARM   ABSTIME ONE-SHOT timer fired early:       0 : [OK]
CLOCK_BOOTTIME_ALARM   ABSTIME ONE-SHOT max latency:     601401 ns : [OK]
CLOCK_BOOTTIME_ALARM   ABSTIME ONE-SHOT count:                   1 : [OK]
CLOCK_BOOTTIME_ALARM   RELTIME ONE-SHOT timer fired early:       0 : [OK]
CLOCK_BOOTTIME_ALARM   RELTIME ONE-SHOT max latency:     628175 ns : [OK]
CLOCK_BOOTTIME_ALARM   RELTIME ONE-SHOT count:                   1 : [OK]
CLOCK_TAI              ABSTIME PERIODIC timer fired early:       0 : [OK]
CLOCK_TAI              ABSTIME PERIODIC max latency: 4295577120 ns : [FAILED]
CLOCK_TAI              RELTIME PERIODIC timer fired early:       0 : [OK]
CLOCK_TAI              RELTIME PERIODIC max latency:     921184 ns : [OK]
CLOCK_TAI              ABSTIME ONE-SHOT timer fired early:       0 : [OK]
CLOCK_TAI              ABSTIME ONE-SHOT max latency:     590048 ns : [OK]
CLOCK_TAI              ABSTIME ONE-SHOT count:                   1 : [OK]
CLOCK_TAI              RELTIME ONE-SHOT timer fired early:       0 : [OK]
CLOCK_TAI              RELTIME ONE-SHOT max latency:    1007202 ns : [OK]
CLOCK_TAI              RELTIME ONE-SHOT count:                   1 : [OK]
# Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
```

So there is some odd stuff going on in how the time comparisons are done of 32 bit builds.

Looks like there is some integer overflow on 32 bit builds in the timespec_sub function:

long long timespec_sub(struct timespec a, struct timespec b) {
long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;

ret -= NSEC_PER_SEC * a.tv_sec + a.tv_nsec;
return ret;
}

on 32 bit builds NSEC_PER_SEC and b.tv_sec are only 32 bit values which I'm guessing is causing the overflow.

NSEC_PER_SEC is defined as 1000000000L but if we change this to 1000000000LL then the test starts passing.

Thomas Gleixner <[email protected]> 於 2025年8月6日 週三 下午4:55寫道:

Quoted 27 lines · Wake Liu
Quoted 3 lines

The constant NSEC_PER_SEC (1,000,000,000) is defined as a long literal. On 32-bit systems like arm32, where long is 32 bits, this value can overflow when used in 64-bit calculations.

How so? Where is the overflow exactly?

The only usage of NSEC_PER_SEC in the VDSO is:

# git grep NSEC_PER_SEC lib/vdso/
lib/vdso/gettimeofday.c:        ts->tv_sec = sec + __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns);

and __iter_div_u64_rem() is an inline:

static __always_inline u32
__iter_div_u64_rem(u64 dividend, u32 divisor, u64 *remainder)

So how exactly is this causing an overflow?

Also by your description this would be a problem throughout the kernel.

Thanks,

tglx

Signature · 2 lines
Best Regards,
Wake Liu
#4 lore raw

On Sat, Aug 09 2025 at 17:49, Wake Liu wrote:

Please do not top post and trim your replies.

Quoted 5 lines

CLOCK_REALTIME ABSTIME PERIODIC timer fired early: 1 : [FAILED]
Looks like there is some integer overflow on 32 bit builds in the timespec_sub function:

long long timespec_sub(struct timespec a, struct timespec b)

That's in selftests and not in the kernel VDSO code.

Can you please be precise with your subject and changelog? You claimed:

"This can lead to incorrect time calculations within the VDSO"

No, it can't not because the VDSO does not use it that way.

Quoted 9 lines

{
long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;

ret -= NSEC_PER_SEC * a.tv_sec + a.tv_nsec;
return ret;
}

on 32 bit builds NSEC_PER_SEC and b.tv_sec are only 32 bit values which I'm guessing is causing the overflow.

Guessing is not a valid technical problem solving approach.

Quoted 2 lines

NSEC_PER_SEC is defined as 1000000000L but if we change this to 1000000000LL then the test starts passing.

Yes, that function bogus on 32bit.

There are at least ten different ways to implement this function 32-bit safe, but you picked the worst option of all, which breaks the kernel build as you got told by 0-day.

I'm sure you can figure out how to ensure that the multiplication is actually expanding to 64-bit or use some other approach to calculate that delta.

And please make that an inline function and put it into a header file in the timer selftest directory, and replace _all_ copies of it in the various timer tests.

Thanks,

tglx

#5 lore raw

Hi Wake,

Quoted 8 lines · Thomas Gleixner
Quoted 7 lines · Wake Liu

long long timespec_sub(struct timespec a, struct timespec b) {
long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;

ret -= NSEC_PER_SEC * a.tv_sec + a.tv_nsec;
return ret;
}

(...)

Quoted 3 lines

And please make that an inline function and put it into a header file in the timer selftest directory, and replace _all_ copies of it in the various timer tests.

When you create that header file, please add a dedicated definition of NSEC_PER_SEC to it. The selftests shouldn't be using internal kernel headers in the first place. Especially not for a single, trivial constant.

Thomas

author
#6 lore raw

PATCH v2 1/1 selftests/timers: Consolidate and fix 32-bit overflow in timespec_sub

The timespec_sub function, as implemented in several timer selftests, is prone to integer overflow on 32-bit systems.

The calculation NSEC_PER_SEC * b.tv_sec is performed using 32-bit arithmetic, and the result overflows before being stored in the 64-bit ret variable. This leads to incorrect time delta calculations and test failures.

As suggested by tglx, this patch fixes the issue by:

1. Creating a new static inline helper function, timespec_to_ns, which safely converts a timespec to nanoseconds by casting tv_sec to long long before multiplying with NSEC_PER_SEC.

2. Placing the new helper and a rewritten timespec_sub into a common header: tools/testing/selftests/timers/helpers.h.

3. Removing the duplicated, buggy implementations from all timer selftests and replacing them with an #include of the new header.

This consolidates the code and ensures the calculation is correctly performed using 64-bit arithmetic across all tests.

Changes in v2:
- Per tglx's feedback, instead of changing NSEC_PER_SEC globally, this version consolidates the buggy timespec_sub() implementations into a new 32-bit safe inline function in a shared header.
- Amended the commit message to be more descriptive.

---
 .../selftests/timers/alarmtimer-suspend.c     | 15 +++------
 tools/testing/selftests/timers/helpers.h      | 31 +++++++++++++++++++
 tools/testing/selftests/timers/nanosleep.c    |  2 +-
 tools/testing/selftests/timers/nsleep-lat.c   | 12 ++-----
 .../testing/selftests/timers/valid-adjtimex.c |  8 ++---
 5 files changed, 43 insertions(+), 25 deletions(-)
 create mode 100644 tools/testing/selftests/timers/helpers.h
tools/testing/selftests/timers/alarmtimer-suspend.c +4 -11
index a9ef76ea6051..e85ab182abe5 100644
@@ -31,8 +31,9 @@
 #include <include/vdso/time64.h>
 #include <errno.h>
 #include "../kselftest.h"
+#include "helpers.h"
 
-#define UNREASONABLE_LAT (NSEC_PER_SEC * 5) /* hopefully we resume in 5 secs */
+#define UNREASONABLE_LAT (NSEC_PER_SEC * 5LL) /* hopefully we resume in 5 secs */
 
 #define SUSPEND_SECS 15
 int alarmcount;
@@ -70,14 +71,6 @@ char *clockstring(int clockid)
 }
 
 
-long long timespec_sub(struct timespec a, struct timespec b)
-{
-	long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;
-
-	ret -= NSEC_PER_SEC * a.tv_sec + a.tv_nsec;
-	return ret;
-}
-
 int final_ret;
 
 void sigalarm(int signo)
@@ -88,8 +81,8 @@ void sigalarm(int signo)
 	clock_gettime(alarm_clock_id, &ts);
 	alarmcount++;
 
-	delta_ns = timespec_sub(start_time, ts);
-	delta_ns -= NSEC_PER_SEC * SUSPEND_SECS * alarmcount;
+	delta_ns = timespec_sub(ts, start_time);
+	delta_ns -= (long long)NSEC_PER_SEC * SUSPEND_SECS * alarmcount;
 
 	printf("ALARM(%i): %ld:%ld latency: %lld ns ", alarmcount, ts.tv_sec,
 							ts.tv_nsec, delta_ns);
tools/testing/selftests/timers/helpers.h new file +31 -0
new file mode 100644
index 000000000000..652f20247091
@@ -0,0 +1,31 @@
+#ifndef SELFTESTS_TIMERS_HELPERS_H
+#define SELFTESTS_TIMERS_HELPERS_H
+
+#include <time.h>
+
+#ifndef NSEC_PER_SEC
+#define NSEC_PER_SEC 1000000000L
+#endif
+
+/*
+ * timespec_to_ns - Convert timespec to nanoseconds
+ */
+static inline long long timespec_to_ns(const struct timespec *ts)
+{
+	return ((long long) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec;
+}
+
+/*
+ * timespec_sub - Subtract two timespec values
+ *
+ * @a: first timespec
+ * @b: second timespec
+ *
+ * Returns a - b in nanoseconds.
+ */
+static inline long long timespec_sub(struct timespec a, struct timespec b)
+{
+	return timespec_to_ns(&a) - timespec_to_ns(&b);
+}
+
+#endif /* SELFTESTS_TIMERS_HELPERS_H */
tools/testing/selftests/timers/nanosleep.c +1 -1
index 252c6308c569..41c33629d5f0 100644
@@ -138,7 +138,7 @@ int main(int argc, char **argv)
 		fflush(stdout);
 
 		length = 10;
-		while (length <= (NSEC_PER_SEC * 10)) {
+		while (length <= (NSEC_PER_SEC * 10LL)) {
 			ret = nanosleep_test(clockid, length);
 			if (ret == UNSUPPORTED) {
 				ksft_test_result_skip("%-31s\n", clockstring(clockid));
tools/testing/selftests/timers/nsleep-lat.c +3 -9
index de23dc0c9f97..c888a77aab7a 100644
@@ -26,6 +26,7 @@
 #include <signal.h>
 #include <include/vdso/time64.h>
 #include "../kselftest.h"
+#include "helpers.h"
 
 #define UNRESONABLE_LATENCY 40000000 /* 40ms in nanosecs */
 
@@ -74,14 +75,6 @@ struct timespec timespec_add(struct timespec ts, unsigned long long ns)
 }
 
 
-long long timespec_sub(struct timespec a, struct timespec b)
-{
-	long long ret = NSEC_PER_SEC * b.tv_sec + b.tv_nsec;
-
-	ret -= NSEC_PER_SEC * a.tv_sec + a.tv_nsec;
-	return ret;
-}
-
 int nanosleep_lat_test(int clockid, long long ns)
 {
 	struct timespec start, end, target;
@@ -146,7 +139,7 @@ int main(int argc, char **argv)
 			continue;
 
 		length = 10;
-		while (length <= (NSEC_PER_SEC * 10)) {
+		while (length <= (NSEC_PER_SEC * 10LL)) {
 			ret = nanosleep_lat_test(clockid, length);
 			if (ret)
 				break;
@@ -164,3 +157,4 @@ int main(int argc, char **argv)
 
 	ksft_finished();
 }
+
tools/testing/selftests/timers/valid-adjtimex.c +4 -4
index 6b7801055ad1..a61d4b4739a2 100644
@@ -260,16 +260,16 @@ int validate_set_offset(void)
 	if (set_offset(-NSEC_PER_SEC - 1, 1))
 		return -1;
 
-	if (set_offset(5 * NSEC_PER_SEC, 1))
+	if (set_offset(5LL * NSEC_PER_SEC, 1))
 		return -1;
 
-	if (set_offset(-5 * NSEC_PER_SEC, 1))
+	if (set_offset(-5LL * NSEC_PER_SEC, 1))
 		return -1;
 
-	if (set_offset(5 * NSEC_PER_SEC + NSEC_PER_SEC / 2, 1))
+	if (set_offset(5LL * NSEC_PER_SEC + NSEC_PER_SEC / 2, 1))
 		return -1;
 
-	if (set_offset(-5 * NSEC_PER_SEC - NSEC_PER_SEC / 2, 1))
+	if (set_offset(-5LL * NSEC_PER_SEC - NSEC_PER_SEC / 2, 1))
 		return -1;
 
 	if (set_offset(USEC_PER_SEC - 1, 0))
Signature · 1 line
2.51.0.384.g4c02a37b29-goog
#7 lore raw

Re: [PATCH v2] selftests/timers: Consolidate and fix 32-bit overflow in timespec_sub

Quoted 1 line · Wake Liu

The timespec_sub function, as implemented in several timer

timespec_sub()

https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#function-references-in-changelogs

Quoted 8 lines

selftests, is prone to integer overflow on 32-bit systems.

The calculation NSEC_PER_SEC * b.tv_sec is performed using 32-bit arithmetic, and the result overflows before being stored in the 64-bit ret variable. This leads to incorrect time delta calculations and test failures.

As suggested by tglx, this patch fixes the issue by:

s/this patch fixes/fix/

Quoted 8 lines

1. Creating a new static inline helper function, timespec_to_ns, which safely converts a timespec to nanoseconds by casting tv_sec to long long before multiplying with NSEC_PER_SEC.

2. Placing the new helper and a rewritten timespec_sub into a common header: tools/testing/selftests/timers/helpers.h.

Quoted 6 lines

3. Removing the duplicated, buggy implementations from all timer selftests and replacing them with an #include of the new header.

This consolidates the code and ensures the calculation is correctly performed using 64-bit arithmetic across all tests.

This lacks a Signed-off-by.

Quoted 5 lines

Changes in v2:
- Per tglx's feedback, instead of changing NSEC_PER_SEC globally, this version consolidates the buggy timespec_sub() implementations into a new 32-bit safe inline function in a shared header.
- Amended the commit message to be more descriptive.

change logs go behind the '---' separator as they are not part of the commit message. It's documented how to format a change log properly.

tools/testing/selftests/timers/alarmtimer-suspend.c line 36

Quoted 2 lines
tools/testing/selftests/timers/alarmtimer-suspend.c +1 -1
-#define UNREASONABLE_LAT (NSEC_PER_SEC * 5) /* hopefully we resume in 5 secs */
+#define UNREASONABLE_LAT (NSEC_PER_SEC * 5LL) /* hopefully we resume in 5 secs */

How is this change and the pile of similar ones related to $subject and why are they required in the first place?

tools/testing/selftests/timers/helpers.h

Quoted 4 lines

index 000000000000..652f20247091

tools/testing/selftests/timers/helpers.h new file +0 -0
@@ -0,0 +1,31 @@

Lacks a SPDX identifier.

scripts/checkpatch.pl exists for a reason.

Thanks,

tglx

#8 lore raw

Re: [PATCH v2] selftests/timers: Consolidate and fix 32-bit overflow in timespec_sub

Quoted 59 lines · Thomas Gleixner
Quoted 1 line · Wake Liu

The timespec_sub function, as implemented in several timer

timespec_sub()

https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#function-references-in-changelogs

Quoted 8 lines

selftests, is prone to integer overflow on 32-bit systems.

The calculation NSEC_PER_SEC * b.tv_sec is performed using 32-bit arithmetic, and the result overflows before being stored in the 64-bit ret variable. This leads to incorrect time delta calculations and test failures.

As suggested by tglx, this patch fixes the issue by:

s/this patch fixes/fix/

Quoted 8 lines

1. Creating a new static inline helper function, timespec_to_ns, which safely converts a timespec to nanoseconds by casting tv_sec to long long before multiplying with NSEC_PER_SEC.

2. Placing the new helper and a rewritten timespec_sub into a common header: tools/testing/selftests/timers/helpers.h.

Quoted 6 lines

3. Removing the duplicated, buggy implementations from all timer selftests and replacing them with an #include of the new header.

This consolidates the code and ensures the calculation is correctly performed using 64-bit arithmetic across all tests.

This lacks a Signed-off-by.

Quoted 5 lines

Changes in v2:
- Per tglx's feedback, instead of changing NSEC_PER_SEC globally, this version consolidates the buggy timespec_sub() implementations into a new 32-bit safe inline function in a shared header.
- Amended the commit message to be more descriptive.

change logs go behind the '---' separator as they are not part of the commit message. It's documented how to format a change log properly.

tools/testing/selftests/timers/alarmtimer-suspend.c line 36

Quoted 2 lines
tools/testing/selftests/timers/alarmtimer-suspend.c +1 -1
-#define UNREASONABLE_LAT (NSEC_PER_SEC * 5) /* hopefully we resume in 5 secs */
+#define UNREASONABLE_LAT (NSEC_PER_SEC * 5LL) /* hopefully we resume in 5 secs */

How is this change and the pile of similar ones related to $subject and why are they required in the first place?

tools/testing/selftests/timers/helpers.h

Quoted 4 lines

index 000000000000..652f20247091

tools/testing/selftests/timers/helpers.h new file +0 -0
@@ -0,0 +1,31 @@

Lacks a SPDX identifier.

Quoted 5 lines

scripts/checkpatch.pl exists for a reason.

Thanks,

tglx

I also just stumbled into this. However, doing a little bit of research it seems this was introduced by commit 80fa614e2fbc ("selftests: timers:
Remove local NSEC_PER_SEC and USEC_PER_SEC defines"), which explicitly changes the local definitions in favor of the internal kernel header, but that doesn't seem right.

I think we should probably revert that commit instead?

--
Carlos Llamas

#9 lore raw
In reply to Wake Liu
kernel test robot noticed the following build warnings:

Hi Wake,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tip/timers/vdso]
[also build test WARNING on linus/master v6.16 next-20250806] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Wake-Liu/vdso-Define-NSEC_PER_SEC-as-64-bit-to-prevent-overflow/20250806-125650
base:   tip/timers/vdso
patch link:    https://lore.kernel.org/r/20250805162153.952693-1-wakel%40google.com
patch subject: [PATCH] vdso: Define NSEC_PER_SEC as 64-bit to prevent overflow
config: powerpc-randconfig-002-20250807 (https://download.01.org/0day-ci/archive/20250807/[email protected]/config)
compiler: powerpc-linux-gcc (GCC) 10.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250807/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

arch/powerpc/xmon/xmon.c: In function 'show_uptime':

>> arch/powerpc/xmon/xmon.c:1008:27: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'long long int' [-Wformat=]
    1008 |   printf("Uptime: %lu.%.2lu seconds\n", (unsigned long)uptime.tv_sec,
         |                       ~~~~^
         |                           |
         |                           long unsigned int
         |                       %.2llu
    1009 |    ((unsigned long)uptime.tv_nsec / (NSEC_PER_SEC/100)));
         |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                                   |
         |                                   long long int

vim +1008 arch/powerpc/xmon/xmon.c

^1da177e4c3f41 arch/ppc64/xmon/xmon.c   Linus Torvalds       2005-04-16   996  
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18   997  /* Based on uptime_proc_show(). */
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18   998  static void
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18   999  show_uptime(void)
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18  1000  {
f6bd74fa084eb9 arch/powerpc/xmon/xmon.c Arnd Bergmann        2018-06-18  1001  	struct timespec64 uptime;
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18  1002  
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18  1003  	if (setjmp(bus_error_jmp) == 0) {
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18  1004  		catch_memory_errors = 1;
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18  1005  		sync();
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18  1006  
f6bd74fa084eb9 arch/powerpc/xmon/xmon.c Arnd Bergmann        2018-06-18  1007  		ktime_get_coarse_boottime_ts64(&uptime);
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18 @1008  		printf("Uptime: %lu.%.2lu seconds\n", (unsigned long)uptime.tv_sec,
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18  1009  			((unsigned long)uptime.tv_nsec / (NSEC_PER_SEC/100)));
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18  1010  
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18  1011  		sync();
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18  1012  		__delay(200);						\
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18  1013  	}
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18  1014  	catch_memory_errors = 0;
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18  1015  }
59d3391e8cf274 arch/powerpc/xmon/xmon.c Guilherme G. Piccoli 2017-09-18  1016  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#10 lore raw
In reply to Wake Liu
kernel test robot noticed the following build errors:

Hi Wake,

kernel test robot noticed the following build errors:

[auto build test ERROR on tip/timers/vdso]
[also build test ERROR on linus/master v6.16 next-20250806] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Wake-Liu/vdso-Define-NSEC_PER_SEC-as-64-bit-to-prevent-overflow/20250806-125650
base:   tip/timers/vdso
patch link:    https://lore.kernel.org/r/20250805162153.952693-1-wakel%40google.com
patch subject: [PATCH] vdso: Define NSEC_PER_SEC as 64-bit to prevent overflow
config: m68k-randconfig-r064-20250807 (https://download.01.org/0day-ci/archive/20250807/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 9.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250807/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "__udivdi3" [drivers/leds/leds-sun50i-a100.ko] undefined!
>> ERROR: modpost: "__divdi3" [drivers/leds/leds-sun50i-a100.ko] undefined!
>> ERROR: modpost: "__divdi3" [drivers/clk/qcom/clk-spmi-pmic-div.ko] undefined!
>> ERROR: modpost: "__udivdi3" [drivers/tty/serial/8250/8250_bcm7271.ko] undefined!
>> ERROR: modpost: "__divdi3" [drivers/tty/serial/8250/8250_bcm7271.ko] undefined!
>> ERROR: modpost: "__udivdi3" [drivers/spi/spi-axi-spi-engine.ko] undefined!
>> ERROR: modpost: "__divdi3" [drivers/spi/spi-axi-spi-engine.ko] undefined!
>> ERROR: modpost: "__divdi3" [drivers/spi/spi-dw.ko] undefined!
>> ERROR: modpost: "__udivdi3" [drivers/spi/spi-dw.ko] undefined!
>> ERROR: modpost: "__udivdi3" [drivers/input/touchscreen/ads7846.ko] undefined!

WARNING: modpost: suppressed 3 unresolved symbol warnings because there were too many)

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki