From nobody Wed Oct 8 07:37:00 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 336B6269CF1; Tue, 1 Jul 2025 08:58:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360290; cv=none; b=OsFoxMbbN3WF5ri7wJDm/Xb44E6VHft+QwCd4ZetQ2JnozUYu8nsGAx5G46CHZO9gqc6npUKVjh0b6JaSQ2oZdUyGptp/VTGvr2VLV2VMGLAcJUuNwTSDRZKPbGCHoD+mqI8BcGhaT6OqLbBIg/PWj6Yy2zUTfn9fXluSiKYeeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360290; c=relaxed/simple; bh=aGyKXEDWrVl42o1/QdNJRr5JgUP/zN2xT7Z0rsQB31c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BB7lwvXMLBEqmVFWSPbnlUvifUSw5i48K3CuBMxci9aPat6NC2Lp5R26WnvvFJN8e3hhH9Cy4eIQ1zmPstkhWtfQO2N6tb3i8XD1ZsChXuj67c/CYNHVfYjYQfsnUp89k66bvc1o8OMebhtHa+riTP69QL226+eVsMnQXtHDAXs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=viI4fnWD; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=MfsGvuVb; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="viI4fnWD"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MfsGvuVb" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1751360286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zg/MZMVxe4vqEY85XexMl2BL8AO2M+KvX9W8RRyArw0=; b=viI4fnWD/1Y6PNl68cmZZyo1kvryQHq0LjDpVMZ6o3erxo6/lJGaeLD3bgUM4R65s+TZcI B4fUgiaCpsO+11/L/20PjRxzKTCcc45iKgkxyhf3jkv1sT+qM0jSJDQACU0MguKpDi4n5v +GRoXaV8zMA7qdbmb9LKOm9I9XwKGqDdnt1GLg6trH85sVJvNukuZC17Xjhz1HYgD2y+y3 9BOj3l36aBoVCjQ2Bxv0cOytTgYfzfHyUjpcNjPXcv8LvlPNr/i/UHohRKVMNrD5oWOUUj oXSVgVZKCrVCxEKd5inKO/xYMN9JL7uvXLcXF+HLhSbsqLahoVBgSDA0xqENpA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1751360286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zg/MZMVxe4vqEY85XexMl2BL8AO2M+KvX9W8RRyArw0=; b=MfsGvuVbDo+xRfjnkyJ+4QegloQ/rHRy+k+r9C9HO+EKbIE1CUepWx9NQkHpshB0tBpGFw PDU4CG5N/8afO3DA== Date: Tue, 01 Jul 2025 10:57:55 +0200 Subject: [PATCH 01/14] selftests/timers: Add testcase for auxiliary clocks Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250701-vdso-auxclock-v1-1-df7d9f87b9b8@linutronix.de> References: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> In-Reply-To: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> To: Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Shuah Khan , Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Stephen Boyd , Catalin Marinas , Will Deacon , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, Richard Cochran , Christopher Hall , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , Kurt Kanzenbach , Nam Cao , Antoine Tenart , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1751360285; l=9807; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=aGyKXEDWrVl42o1/QdNJRr5JgUP/zN2xT7Z0rsQB31c=; b=O/YV9KTW7oOAMiAf3l56XmU6PUWfqXXfrs2Inr0O+Qs7JtK2sYieB6c7VLlasrdiTp04HhXFz jATsHeEhbjyA5g1BgZQ58/ALT4q+hODXi82draVAffT3PPCpXvV9mFn X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Auxiliary clocks behave differently from regular ones. Add a testcase to validate their functionality. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/testing/selftests/timers/.gitignore | 1 + tools/testing/selftests/timers/Makefile | 2 +- tools/testing/selftests/timers/auxclock.c | 319 ++++++++++++++++++++++++++= ++++ 3 files changed, 321 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/timers/.gitignore b/tools/testing/self= tests/timers/.gitignore index bb5326ff900b8edc3aa2d8d596599973593fbaf0..dcee43b3ecd9351c9bb0483088d= 712ccd7b57367 100644 --- a/tools/testing/selftests/timers/.gitignore +++ b/tools/testing/selftests/timers/.gitignore @@ -20,3 +20,4 @@ valid-adjtimex adjtick set-tz freq-step +auxclock diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selfte= sts/timers/Makefile index 32203593c62e1e0cdfd3de6f567ea1e82913f2ef..3a8833b3fb7449495c66a92c4d8= 2e35a6755b5e8 100644 --- a/tools/testing/selftests/timers/Makefile +++ b/tools/testing/selftests/timers/Makefile @@ -5,7 +5,7 @@ LDLIBS +=3D -lrt -lpthread -lm # these are all "safe" tests that don't modify # system time or require escalated privileges TEST_GEN_PROGS =3D posix_timers nanosleep nsleep-lat set-timer-lat mqueue-= lat \ - inconsistency-check raw_skew threadtest rtcpie + inconsistency-check raw_skew threadtest rtcpie auxclock =20 DESTRUCTIVE_TESTS =3D alarmtimer-suspend valid-adjtimex adjtick change_ske= w \ skew_consistency clocksource-switch freq-step leap-a-day \ diff --git a/tools/testing/selftests/timers/auxclock.c b/tools/testing/self= tests/timers/auxclock.c new file mode 100644 index 0000000000000000000000000000000000000000..0ba2f9996114ade3147f0f3aec4= 9904556a23cd4 --- /dev/null +++ b/tools/testing/selftests/timers/auxclock.c @@ -0,0 +1,319 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Work around type conflicts between libc and the UAPI headers */ +#define _SYS_TIME_H +#define __timeval_defined +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include + +#include "../kselftest_harness.h" + +#ifndef CLOCK_AUX +#define CLOCK_AUX 16 +#endif + +#ifndef NSEC_PER_SEC +#define NSEC_PER_SEC 1000000000ULL +#endif + +#define AUXCLOCK_SELFTEST_TIMENS_OFFSET 10000 + +static int configure_auxclock(__kernel_clockid_t clockid, bool enable) +{ + char path[100]; + int fd, ret; + + ret =3D snprintf(path, sizeof(path), + "/sys/kernel/time/aux_clocks/%d/aux_clock_enable", + (int)clockid - CLOCK_AUX); + if (ret >=3D sizeof(path)) + return -ENOSPC; + + fd =3D open(path, O_WRONLY); + if (fd =3D=3D -1) + return -errno; + + /* Always disable to reset */ + ret =3D dprintf(fd, "0\n"); + if (enable) + ret =3D dprintf(fd, "1\n"); + close(fd); + + if (ret < 0) + return ret; + + return 0; +} + +/* Everything is done in terms of 64bit time values to keep the code reada= ble */ + +static inline void timespec_to_kernel_timespec(const struct timespec *ts, + struct __kernel_timespec *kts) +{ + if (!kts) + return; + + kts->tv_sec =3D ts->tv_sec; + kts->tv_nsec =3D ts->tv_nsec; +} + +static inline void kernel_timespec_to_timespec(const struct __kernel_times= pec *kts, + struct timespec *ts) +{ + if (!kts) + return; + + ts->tv_sec =3D kts->tv_sec; + ts->tv_nsec =3D kts->tv_nsec; +} + +static int sys_clock_getres_time64(__kernel_clockid_t clockid, struct __ke= rnel_timespec *ts) +{ +#if defined(__NR_clock_getres_time64) + return syscall(__NR_clock_getres_time64, clockid, ts); +#elif defined(__NR_clock_getres) + struct timespec _ts; + int ret; + + ret =3D syscall(__NR_clock_getres, clockid, &_ts); + if (!ret) + timespec_to_kernel_timespec(&_ts, ts); + return ret; +#else +#error "No clock_getres() support" +#endif +} + +static int sys_clock_gettime64(__kernel_clockid_t clockid, struct __kernel= _timespec *ts) +{ +#if defined(__NR_clock_gettime64) + return syscall(__NR_clock_gettime64, clockid, ts); +#elif defined(__NR_clock_gettime) + struct timespec _ts; + int ret; + + ret =3D syscall(__NR_clock_gettime, clockid, &_ts); + if (!ret) + timespec_to_kernel_timespec(&_ts, ts); + return ret; +#else +#error "No clock_gettime() support" +#endif +} + +static int sys_clock_settime64(__kernel_clockid_t clockid, const struct __= kernel_timespec *ts) +{ +#if defined(__NR_clock_settime64) + return syscall(__NR_clock_settime64, clockid, ts); +#elif defined(__NR_clock_settime) + struct timespec _ts; + + kernel_timespec_to_timespec(ts, &_ts); + return syscall(__NR_clock_settime, clockid, &_ts); +#else +#error "No clock_settime() support" +#endif +} + +static int sys_clock_adjtime64(__kernel_clockid_t clockid, struct __kernel= _timex *tx) +{ +#if defined(__NR_clock_adjtime64) + return syscall(__NR_clock_adjtime64, clockid, tx); +#elif __LONG_WIDTH__ =3D=3D 64 && defined(__NR_clock_adjtime) + return syscall(__NR_clock_adjtime, clockid, tx); +#else +#error "No clock_adjtime() support" +#endif +} + +FIXTURE(auxclock) {}; + +FIXTURE_VARIANT(auxclock) { + __kernel_clockid_t clock; + bool clock_enabled; + bool use_timens; +}; + +FIXTURE_VARIANT_ADD(auxclock, default) { + .clock =3D CLOCK_AUX, + .clock_enabled =3D true, + .use_timens =3D false, +}; + +FIXTURE_VARIANT_ADD(auxclock, timens) { + .clock =3D CLOCK_AUX, + .clock_enabled =3D true, + .use_timens =3D true, +}; + +FIXTURE_VARIANT_ADD(auxclock, disabled) { + .clock =3D CLOCK_AUX, + .clock_enabled =3D false, + .use_timens =3D false, +}; + +/* No timens_disabled to keep the testmatrix smaller. */ + +static void enter_timens(struct __test_metadata *_metadata) +{ + int ret, fd; + char buf[100]; + + ret =3D unshare(CLONE_NEWTIME); + if (ret !=3D 0 && errno =3D=3D EPERM) + SKIP(return, "no permissions for unshare(CLONE_NEWTIME)"); + if (ret !=3D 0 && errno =3D=3D EINVAL) + SKIP(return, "time namespaces not available"); + ASSERT_EQ(0, ret) TH_LOG("unshare(CLONE_NEWTIME) failed: %s", strerror(er= rno)); + fd =3D open("/proc/self/timens_offsets", O_WRONLY); + if (fd =3D=3D -1 && errno =3D=3D ENOENT) + SKIP(return, "no support for time namespaces"); + ASSERT_NE(-1, fd); + /* Fiddle with the namespace to make the tests more meaningful */ + ret =3D snprintf(buf, sizeof(buf), "monotonic %d 0\nboottime %d 0\n", + AUXCLOCK_SELFTEST_TIMENS_OFFSET, AUXCLOCK_SELFTEST_TIMENS_OFFSET); + ASSERT_TRUE(ret > 0 && ret < sizeof(buf)); + ret =3D write(fd, buf, ret); + ASSERT_NE(-1, ret); + close(fd); + fd =3D open("/proc/self/ns/time_for_children", O_RDONLY); + ASSERT_NE(-1, fd); + ret =3D setns(fd, CLONE_NEWTIME); + close(fd); + ASSERT_EQ(0, ret); +} + +FIXTURE_SETUP(auxclock) { + int ret; + + ret =3D configure_auxclock(variant->clock, variant->clock_enabled); + if (ret =3D=3D -ENOENT) + SKIP(return, "auxclocks not enabled"); + ASSERT_EQ(0, ret); + + if (variant->use_timens) + enter_timens(_metadata); +} + +FIXTURE_TEARDOWN(auxclock) { + int ret; + + ret =3D configure_auxclock(variant->clock, false); + ASSERT_EQ(0, ret); +} + +TEST_F(auxclock, sys_clock_getres) { + struct __kernel_timespec ts; + int ret; + + /* clock_getres() is always expected to work */ + ret =3D sys_clock_getres_time64(variant->clock, &ts); + ASSERT_EQ(0, ret); + ASSERT_EQ(0, ts.tv_sec); + ASSERT_EQ(1, ts.tv_nsec); +} + +TEST_F(auxclock, sys_clock_gettime) { + struct __kernel_timespec ts; + int ret; + + ret =3D sys_clock_gettime64(variant->clock, &ts); + if (variant->clock_enabled) { + ASSERT_EQ(0, ret); + } else { + ASSERT_EQ(-1, ret); + ASSERT_EQ(ENODEV, errno); + } +} + +static void auxclock_validate_progression(struct __test_metadata *_metadat= a, + const struct __kernel_timespec *a, + const struct __kernel_timespec *b) +{ + int64_t diff; + + diff =3D (b->tv_sec - a->tv_sec) * NSEC_PER_SEC; + diff +=3D b->tv_nsec - a->tv_nsec; + + /* Arbitrary values */ + ASSERT_LT(1, diff); + ASSERT_GT(1 * NSEC_PER_SEC, diff); +} + +TEST_F(auxclock, sys_clock_settime) { + struct __kernel_timespec a, b =3D {}; + int ret; + + a.tv_sec =3D 1234; + a.tv_nsec =3D 5678; + + ret =3D sys_clock_settime64(variant->clock, &a); + if (!variant->clock_enabled) { + ASSERT_EQ(-1, ret); + ASSERT_EQ(ENODEV, errno); + return; + } + + ASSERT_EQ(0, ret); + + ret =3D sys_clock_gettime64(variant->clock, &b); + ASSERT_EQ(0, ret); + + auxclock_validate_progression(_metadata, &a, &b); +} + +TEST_F(auxclock, sys_clock_adjtime) { + struct __kernel_timex tx; + int ret, realtime_freq; + + memset(&tx, 0, sizeof(tx)); + tx.modes =3D ADJ_FREQUENCY; + ret =3D sys_clock_adjtime64(CLOCK_REALTIME, &tx); + ASSERT_NE(-1, ret); + ASSERT_TRUE(tx.modes & ADJ_FREQUENCY); + realtime_freq =3D tx.freq; + + ret =3D sys_clock_adjtime64(variant->clock, &tx); + if (variant->clock_enabled) { + ASSERT_NE(-1, ret); + ASSERT_EQ(realtime_freq, tx.freq); + } else { + ASSERT_EQ(-1, ret); + ASSERT_EQ(ENODEV, errno); + } +} + +TEST_F(auxclock, progression) { + struct __kernel_timespec a, b; + int ret; + + if (!variant->clock_enabled) { + TH_LOG("no progression on disabled clocks"); + return; + } + + /* set up reference */ + ret =3D sys_clock_gettime64(variant->clock, &a); + ASSERT_EQ(0, ret); + + for (int i =3D 0; i < 100; i++) { + memset(&b, 0, sizeof(b)); + ret =3D sys_clock_gettime64(variant->clock, &b); + ASSERT_EQ(0, ret); + auxclock_validate_progression(_metadata, &a, &b); + + memset(&a, 0, sizeof(a)); + ret =3D sys_clock_gettime64(variant->clock, &a); + ASSERT_EQ(0, ret); + auxclock_validate_progression(_metadata, &b, &a); + } +} + +TEST_HARNESS_MAIN --=20 2.50.0 From nobody Wed Oct 8 07:37:00 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3364E269CE5; Tue, 1 Jul 2025 08:58:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360289; cv=none; b=pqhchpC/Hnuidc9FTle4bCGgLiAJUyurHy6A3oRzIceBxh+x27RzGu5A7LhcxEZzs3waesG2ujtxClzSsUF80fKa67pD0KTl897yIJZ9bOJLXN9siaWyvvhyw6wyDgDdjDvqNK46st8+IJBFVgkqW/gcK+X0lJrabKcjZ1ADpdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360289; c=relaxed/simple; bh=O+pdqhovJ5sCWr6cbVQYxtHMRmPHnT/rOYl0Ec66rdg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ag5fVhsu+aVFOHA1oYpyLDuoIEkgFpDSwOLYflO8N2HN0OROgn09BYkYbibARkODwCUktEbHX703HPc6zBf2wNBlsLKprlAOvr1wH9XOggt9GWFST6CoxJkrcVwC5xz5KS3MuRkeuM2YhOqs8Og70ve++rpXMe3Rxy9wIXGvyyg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Cvfq+ShZ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=sgmfuKLl; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Cvfq+ShZ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sgmfuKLl" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1751360286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6zypL7Z/iJT9pt/jkPKsLbW/urAL7A4U3k+sv3E7jTg=; b=Cvfq+ShZBlRpqLEBOnn8FpMD0gK9w7CyXjIFIZyjrEoM5IoNGvRbep0gq3pyn8BIui/Kxk A2ViNmKpkZH3NAdGzCMMSnEmMhFfJ7Duypk+z7Ll3zCgk+TAscf2ipjjyetPBEQXzSBbC+ 080IcZD8bWfUkplxeUn94zbQD8NxbmiybQ5LND26COt6UwpdzUostFo8qh30YjPMwhRgKz 5V3+YoJ5WGXZnEhhocJjZ7gokZtoaqaU9m0iwvEHUGkqKJ2qY99XWY0Wdjb+Bhml8q+g9J GhWElpAyu+wNRJ40rjxUxuo2hMiFJ4JDrZ8bg7wScZFxRqtQnamLnOpobO9X0g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1751360286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6zypL7Z/iJT9pt/jkPKsLbW/urAL7A4U3k+sv3E7jTg=; b=sgmfuKLl97WFPgJQ2Cl1kAqQzhUmEQJC6TCmpkh3zY+DwrRRPYl9zbjgCqmJcyT/Wiqf4S jPoLsppETFf6eeBg== Date: Tue, 01 Jul 2025 10:57:56 +0200 Subject: [PATCH 02/14] vdso/vsyscall: Introduce a helper to fill clock configurations Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250701-vdso-auxclock-v1-2-df7d9f87b9b8@linutronix.de> References: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> In-Reply-To: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> To: Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Shuah Khan , Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Stephen Boyd , Catalin Marinas , Will Deacon , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, Richard Cochran , Christopher Hall , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , Kurt Kanzenbach , Nam Cao , Antoine Tenart , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1751360285; l=2069; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=O+pdqhovJ5sCWr6cbVQYxtHMRmPHnT/rOYl0Ec66rdg=; b=p8vqvlzZbfPJuNB7hzPJj8dga3B+cwPmwh+UN2KNgYAAY1i/FYSqtwEPROhvYlPu5RH0FZzN+ FzVHcGeNczjCyKAn7W8w6ERqHRSTH7MY5nl/wpUomcMyoG9AGWRKpyy X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The logic to configure a 'struct vdso_clock' from a 'struct tk_read_base' is copied two times. Split it into a shared function to reduce the duplication, especially as another user will be added for auxiliary clocks. Signed-off-by: Thomas Wei=C3=9Fschuh --- kernel/time/vsyscall.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/kernel/time/vsyscall.c b/kernel/time/vsyscall.c index 32ef27c71b57aaa4ed898c0dbfdefcb73b8ff56a..d655df2597336f7305bfc74e2a8= 7c651f314267b 100644 --- a/kernel/time/vsyscall.c +++ b/kernel/time/vsyscall.c @@ -15,26 +15,25 @@ =20 #include "timekeeping_internal.h" =20 +static inline void fill_clock_configuration(struct vdso_clock *vc, const s= truct tk_read_base *base) +{ + vc->cycle_last =3D base->cycle_last; +#ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT + vc->max_cycles =3D base->clock->max_cycles; +#endif + vc->mask =3D base->mask; + vc->mult =3D base->mult; + vc->shift =3D base->shift; +} + static inline void update_vdso_time_data(struct vdso_time_data *vdata, str= uct timekeeper *tk) { struct vdso_clock *vc =3D vdata->clock_data; struct vdso_timestamp *vdso_ts; u64 nsec, sec; =20 - vc[CS_HRES_COARSE].cycle_last =3D tk->tkr_mono.cycle_last; -#ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT - vc[CS_HRES_COARSE].max_cycles =3D tk->tkr_mono.clock->max_cycles; -#endif - vc[CS_HRES_COARSE].mask =3D tk->tkr_mono.mask; - vc[CS_HRES_COARSE].mult =3D tk->tkr_mono.mult; - vc[CS_HRES_COARSE].shift =3D tk->tkr_mono.shift; - vc[CS_RAW].cycle_last =3D tk->tkr_raw.cycle_last; -#ifdef CONFIG_GENERIC_VDSO_OVERFLOW_PROTECT - vc[CS_RAW].max_cycles =3D tk->tkr_raw.clock->max_cycles; -#endif - vc[CS_RAW].mask =3D tk->tkr_raw.mask; - vc[CS_RAW].mult =3D tk->tkr_raw.mult; - vc[CS_RAW].shift =3D tk->tkr_raw.shift; + fill_clock_configuration(&vc[CS_HRES_COARSE], &tk->tkr_mono); + fill_clock_configuration(&vc[CS_RAW], &tk->tkr_raw); =20 /* CLOCK_MONOTONIC */ vdso_ts =3D &vc[CS_HRES_COARSE].basetime[CLOCK_MONOTONIC]; --=20 2.50.0 From nobody Wed Oct 8 07:37:00 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9695D26A08C; Tue, 1 Jul 2025 08:58:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360290; cv=none; b=sCFkIyBzxNLRIcY7Sq3hxu3ix5ydQGpm0Ujw5S7CREXUqpUMbHgl/h2Uqv8Ru5znGQmfdbl1J1IgEjfQrfO5LwIIxuOU/eoQxQs3aNgbiSoXYqUVLr9qerdVXG0Zl3CJWnDZgq2/ruDgyw9JIdLhpPkdVgLlZyAKpIGWJsPKfAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360290; c=relaxed/simple; bh=7aTgq0KSjM6EGaXtNhSs9nQlKXik5A0X/dUKdIChsT0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qBpcUNKvwP8mZFbiUFMOfqrNjJPJm6Q1H9tfDLj5+lp5LojLWq/JTzBeHZqvTkPi3MusiBNh1vQeplwIGrkkS+SEbJCl+GFHd0wGJBFjeECHpxEeYVutqBe0GQVBBN/Ra1Qk1Kd0dFHE1vJGhYHD6V8D35mwG1Dz6bDq0hVFZnE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yHKwD2Q5; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=AuFZMdoz; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yHKwD2Q5"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="AuFZMdoz" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1751360286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z+04s1T3yXqZrrf3aK3nXtq7h92lG6xtvLkzD/OirFg=; b=yHKwD2Q5pHM3DAgZXj244Xh5OLAiiOnolD2S6MvXgxek2cL49J3kEGXFMBeYnVwMjx2sqS 33DUSS9tBcITt0bjfFYgqmKnhlNrnwH1m5oQAtDE9JLICsHFsRdJXnsAhzaLXdUVA9e7ho /Af4JFo4ZfqQBpfnBjBdXJk5CzetI9Mi9rJomFbdbBjucV5OObAQC3DGQJMI8YoMr6xKRs 6gV71fi7QVahC5ZFwPhf8vhMooaJMDfhBdG2V2rAPLurOX6x0VqAeOUbe68V6YqifvzBom irSv4Rt84flYLCHMQWsQc0ZKkVOJrcfFZ/GjVfNqcaDe/X2/Vj6NdNtrarukqQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1751360286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z+04s1T3yXqZrrf3aK3nXtq7h92lG6xtvLkzD/OirFg=; b=AuFZMdozwhxxl4czhHsrAJjfJ6FrL8qsqQQWXGRVIwh1aHSCVfgD9N2IxH9pBDeor0f1os H3cU/qtRD96lhRAQ== Date: Tue, 01 Jul 2025 10:57:57 +0200 Subject: [PATCH 03/14] vdso/vsyscall: Split up __arch_update_vsyscall() into __arch_update_vdso_clock() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250701-vdso-auxclock-v1-3-df7d9f87b9b8@linutronix.de> References: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> In-Reply-To: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> To: Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Shuah Khan , Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Stephen Boyd , Catalin Marinas , Will Deacon , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, Richard Cochran , Christopher Hall , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , Kurt Kanzenbach , Nam Cao , Antoine Tenart , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1751360285; l=2862; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=7aTgq0KSjM6EGaXtNhSs9nQlKXik5A0X/dUKdIChsT0=; b=5+hqp1gTVgnk3Y+ZA8yf+WT55NlfCoI2CtKaCxxJB92agsCM4gnSJpWL0J1ICnFCSb6eFEGuc CTULiQ+9dTBBGkm84WQcYFGeX83ew8QQHoSPXfu1uq4UoUqki8d8Peh X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The upcoming auxiliary clocks need this hook, too. To separate the architecture hooks from the timekeeper internals, refactor the hook to only operate on a single vDSO clock. While at it, use a more robust #define for the hook override. Signed-off-by: Thomas Wei=C3=9Fschuh --- arch/arm64/include/asm/vdso/vsyscall.h | 7 +++---- include/asm-generic/vdso/vsyscall.h | 6 +++--- kernel/time/vsyscall.c | 3 ++- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/vdso/vsyscall.h b/arch/arm64/include/as= m/vdso/vsyscall.h index de58951b8df6a4bb9afd411878793c79c30adbf2..417aae5763a86f39acffe1e6f96= cb0e57212d04b 100644 --- a/arch/arm64/include/asm/vdso/vsyscall.h +++ b/arch/arm64/include/asm/vdso/vsyscall.h @@ -13,12 +13,11 @@ * Update the vDSO data page to keep in sync with kernel timekeeping. */ static __always_inline -void __arm64_update_vsyscall(struct vdso_time_data *vdata) +void __arch_update_vdso_clock(struct vdso_clock *vc) { - vdata->clock_data[CS_HRES_COARSE].mask =3D VDSO_PRECISION_MASK; - vdata->clock_data[CS_RAW].mask =3D VDSO_PRECISION_MASK; + vc->mask =3D VDSO_PRECISION_MASK; } -#define __arch_update_vsyscall __arm64_update_vsyscall +#define __arch_update_vdso_clock __arch_update_vdso_clock =20 /* The asm-generic header needs to be included after the definitions above= */ #include diff --git a/include/asm-generic/vdso/vsyscall.h b/include/asm-generic/vdso= /vsyscall.h index b550afa15ecd101d821f51ce9105903978dced40..7fc0b560007dd8f09a2f24ace76= ce68579ad17c1 100644 --- a/include/asm-generic/vdso/vsyscall.h +++ b/include/asm-generic/vdso/vsyscall.h @@ -22,11 +22,11 @@ static __always_inline const struct vdso_rng_data *__ar= ch_get_vdso_u_rng_data(vo =20 #endif /* CONFIG_GENERIC_VDSO_DATA_STORE */ =20 -#ifndef __arch_update_vsyscall -static __always_inline void __arch_update_vsyscall(struct vdso_time_data *= vdata) +#ifndef __arch_update_vdso_clock +static __always_inline void __arch_update_vdso_clock(struct vdso_clock *vc) { } -#endif /* __arch_update_vsyscall */ +#endif /* __arch_update_vdso_clock */ =20 #ifndef __arch_sync_vdso_time_data static __always_inline void __arch_sync_vdso_time_data(struct vdso_time_da= ta *vdata) diff --git a/kernel/time/vsyscall.c b/kernel/time/vsyscall.c index d655df2597336f7305bfc74e2a87c651f314267b..df6bada2d58ed9a03e5dd3cb4b2= 18983089a2877 100644 --- a/kernel/time/vsyscall.c +++ b/kernel/time/vsyscall.c @@ -118,7 +118,8 @@ void update_vsyscall(struct timekeeper *tk) if (clock_mode !=3D VDSO_CLOCKMODE_NONE) update_vdso_time_data(vdata, tk); =20 - __arch_update_vsyscall(vdata); + __arch_update_vdso_clock(&vc[CS_HRES_COARSE]); + __arch_update_vdso_clock(&vc[CS_RAW]); =20 vdso_write_end(vdata); =20 --=20 2.50.0 From nobody Wed Oct 8 07:37:00 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF23B26A0B3; Tue, 1 Jul 2025 08:58:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360290; cv=none; b=U45tuArxaDw6vJtmIHmD6GYd4DCgAJcylUiIpyOGsmIvECxGcw8QJ6PFxMLQCfUGUkbXiOzngjzYW1TToZvLonnc3/ThiqruK7RUDHr2RpOVwAx4rYuW+4EhjNROQhdWP1hz9EN4akgf8WjLQWDxsmYbf3gc7GQVynX9xTc+D3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360290; c=relaxed/simple; bh=sd/v7cGkj/tjrSz2ZYvXIB3XB5Mae2DoLyqaD2YDD50=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Dtxwwjd2Rtjunz4+2jkUX6y/1+8YcXSXp5avR1rvTbPbEnVwNkQhv4lDXmWvh2eDivVtwRqiXdb7GzgmGYe6PzyxRyQc7rANsH2+iO7t4pUWNcqb21h2scklIGiTPN5VKNnQQ9UMebkeMJ/Wa1FjP569n+CNnosCLBw/xCgugu4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=krhzk1D7; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xmufFQQ4; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="krhzk1D7"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xmufFQQ4" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1751360287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=joYJ/MT5CmKtbgnKXRG/YOnvLpHO2Kz90MtG4Gjijrg=; b=krhzk1D7lMKjKujXnkLtewos+ZEzFtnviygSNaOH81NLdcFvKN/5rDRHKcXOviJlF3+ScF sSILpbPEvg02UQ1tMXjR5TaSdR/FfpEQQqNmxduF9+Ik3MltL4gtmiTPuYMBbT6NeHj/05 A3uixZ4X0oVqt3aL+jlBkOEGFbdSJvTlpGtuHIpX7MX93qQdlwlv1aQSBYGRWGbiXcqsmQ g2Dgs2/mnFTJpWcmNXUDJaA+lnr+OK6wH5Ml/yKwi7detYOtAGVs/lDEe9ZV8sPaucJVAh BBwMxWYo4/YRtsZk1pdnC/QcBBaBwHLByplJSYT7HkirgcFaobHSVwpbFaWTrw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1751360287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=joYJ/MT5CmKtbgnKXRG/YOnvLpHO2Kz90MtG4Gjijrg=; b=xmufFQQ4bBO6kk1ikyfHdIQHNbO5pST5YTXQizxVBEE+zeJrwv081AC82PS6mNifoki68y WZNpjH/czo0tVLAg== Date: Tue, 01 Jul 2025 10:57:58 +0200 Subject: [PATCH 04/14] vdso/helpers: Add helpers for seqlocks of single vdso_clock Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250701-vdso-auxclock-v1-4-df7d9f87b9b8@linutronix.de> References: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> In-Reply-To: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> To: Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Shuah Khan , Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Stephen Boyd , Catalin Marinas , Will Deacon , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, Richard Cochran , Christopher Hall , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , Kurt Kanzenbach , Nam Cao , Antoine Tenart , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1751360285; l=2571; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=sd/v7cGkj/tjrSz2ZYvXIB3XB5Mae2DoLyqaD2YDD50=; b=xHNJy1mqucZQ/T+0vCZcI6A5yV4d5Wm2CvBT6moVq8zEmS9PmdFRxsLmxUq/vJzGB524dlpsL qipcU3XvOpkCtiYJVJhEl2zHKlPnzAMS3lIQiV9mGiAkdtMch9Ht/rp X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Auxiliary clocks will have their vDSO data in a dedicated 'struct vdso_cloc= k', which needs to be synchronized independently. Add a helper to synchronize a single vDSO clock. Signed-off-by: Thomas Wei=C3=9Fschuh --- include/vdso/helpers.h | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/include/vdso/helpers.h b/include/vdso/helpers.h index 0a98fed550ba66a84a620fbbd6aee3e3029b4772..a5679f5efdfdcaaf6efd5f4a317= d1f132c3dc617 100644 --- a/include/vdso/helpers.h +++ b/include/vdso/helpers.h @@ -28,32 +28,46 @@ static __always_inline u32 vdso_read_retry(const struct= vdso_clock *vc, return seq !=3D start; } =20 -static __always_inline void vdso_write_begin(struct vdso_time_data *vd) +static __always_inline void vdso_write_begin_clock(struct vdso_clock *vc, = bool last) { - struct vdso_clock *vc =3D vd->clock_data; - /* * WRITE_ONCE() is required otherwise the compiler can validly tear - * updates to vd[x].seq and it is possible that the value seen by the + * updates to vc->seq and it is possible that the value seen by the * reader is inconsistent. */ - WRITE_ONCE(vc[CS_HRES_COARSE].seq, vc[CS_HRES_COARSE].seq + 1); - WRITE_ONCE(vc[CS_RAW].seq, vc[CS_RAW].seq + 1); - smp_wmb(); + WRITE_ONCE(vc->seq, vc->seq + 1); + + if (last) + smp_wmb(); } =20 -static __always_inline void vdso_write_end(struct vdso_time_data *vd) +static __always_inline void vdso_write_end_clock(struct vdso_clock *vc, bo= ol first) { - struct vdso_clock *vc =3D vd->clock_data; + if (first) + smp_wmb(); =20 - smp_wmb(); /* * WRITE_ONCE() is required otherwise the compiler can validly tear - * updates to vd[x].seq and it is possible that the value seen by the + * updates to vc->seq and it is possible that the value seen by the * reader is inconsistent. */ - WRITE_ONCE(vc[CS_HRES_COARSE].seq, vc[CS_HRES_COARSE].seq + 1); - WRITE_ONCE(vc[CS_RAW].seq, vc[CS_RAW].seq + 1); + WRITE_ONCE(vc->seq, vc->seq + 1); +} + +static __always_inline void vdso_write_begin(struct vdso_time_data *vd) +{ + struct vdso_clock *vc =3D vd->clock_data; + + vdso_write_begin_clock(&vc[CS_HRES_COARSE], false); + vdso_write_begin_clock(&vc[CS_RAW], true); +} + +static __always_inline void vdso_write_end(struct vdso_time_data *vd) +{ + struct vdso_clock *vc =3D vd->clock_data; + + vdso_write_end_clock(&vc[CS_HRES_COARSE], true); + vdso_write_end_clock(&vc[CS_RAW], false); } =20 #endif /* !__ASSEMBLY__ */ --=20 2.50.0 From nobody Wed Oct 8 07:37:00 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11F0C26D4D4; Tue, 1 Jul 2025 08:58:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360292; cv=none; b=XVzs1ZkrC3KbHsYewYyiZ1TV/C/waw4Ev8ry4Drce9EfpFhGG/hEyn692rt4Gla12q7Jgo0WbN38bw1AfE+X/Uk0iXyjy+3vQ9u1P0INEVokIqp+sztPribZrHhOpSJugY8obCz8y9ACOxqhjQmSUHDONK6Hy3xgM9+zzH0hUsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360292; c=relaxed/simple; bh=WrNmDq00XPL9/kcKPoWaUE05zyuMZ1wASlKqJKUZvV4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FwY+XhfXMMIj9/wV8RL88hbAg+OYdR8I0gvYVFfFLXzkuTkQJAON0tQxpdZWe6ttYRc3yt7iRSwaHoKJBemQwLzsHo+vCCZC6peReLlBK1aFj4qKB3LsQr42el7fOce/3o7WSRxNpkNE4OJM58BPOOLw58xlTxdOf+6+bSLDpOA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Q3Bq7jJD; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=5bleG6OH; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Q3Bq7jJD"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="5bleG6OH" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1751360287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EjeWk9zqwweIgociDbPCS45o0KwQTUtlv3dSFR85Uf8=; b=Q3Bq7jJDuyJYZZNBtxqwLQORnk+1VWGdxJ5VZ/5n8JC/Mp6Fh3IvRjPoe8G8c0J+O4T5VE KiXJoAnvbFFP+I9owauyAUuofSNFbRFmNmAAlI/WXPdFRPZDl53qNiW6E27P3L/ZMBI16s qBqoY0bkaLg4ux9pXGa3+j+8s4HtxsXK9Ucwf07oYqOx4pM5NJCPGma7zvJHD6T7NV5kWU 6snc5AaEYoCE6BEb9WUvw6WQ0iJAii/iN7RA+ekjlYTBxiU0cDl0XejtXF5qlD5RCkEFHF mZoDHsqrvQPWbssyF7Qg4Y4QJvS9uLooQRwRkXv/zzc6th7h3hgqCnLvgMYu7w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1751360287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EjeWk9zqwweIgociDbPCS45o0KwQTUtlv3dSFR85Uf8=; b=5bleG6OHL3bnoymfUdalPRYi3NtkgJM/zEM5og7glKoX+JQWYLzWp5LXRyJEIBHoy0aVuP xxQtI3Ds9lIF9eCg== Date: Tue, 01 Jul 2025 10:57:59 +0200 Subject: [PATCH 05/14] vdso/gettimeofday: Return bool from clock_getres() helpers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250701-vdso-auxclock-v1-5-df7d9f87b9b8@linutronix.de> References: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> In-Reply-To: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> To: Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Shuah Khan , Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Stephen Boyd , Catalin Marinas , Will Deacon , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, Richard Cochran , Christopher Hall , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , Kurt Kanzenbach , Nam Cao , Antoine Tenart , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1751360285; l=2609; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=WrNmDq00XPL9/kcKPoWaUE05zyuMZ1wASlKqJKUZvV4=; b=tN3l3TzL2aN33IdNstQl9X9W45CCH/yMvg2ndeJaAOtYqHqBFxk+zMlSkxDO3EBvMH4sMt5em LTTGotpyffNDjM9h5UsfpqDXNLO0vxPFLzrx5nuppVM50KXpkxEBIh0 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The internal helpers are effectively using boolean results, while pretending to use error numbers. Switch the return type to bool for more clarity. Signed-off-by: Thomas Wei=C3=9Fschuh --- lib/vdso/gettimeofday.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c index 93ef801a97ef25f66195490d14e41bebcd41982b..9b77f23566f6a35887d4c9aaefc= 61a971131b499 100644 --- a/lib/vdso/gettimeofday.c +++ b/lib/vdso/gettimeofday.c @@ -396,8 +396,8 @@ static __maybe_unused __kernel_old_time_t __cvdso_time(= __kernel_old_time_t *time =20 #ifdef VDSO_HAS_CLOCK_GETRES static __maybe_unused -int __cvdso_clock_getres_common(const struct vdso_time_data *vd, clockid_t= clock, - struct __kernel_timespec *res) +bool __cvdso_clock_getres_common(const struct vdso_time_data *vd, clockid_= t clock, + struct __kernel_timespec *res) { const struct vdso_clock *vc =3D vd->clock_data; u32 msk; @@ -405,7 +405,7 @@ int __cvdso_clock_getres_common(const struct vdso_time_= data *vd, clockid_t clock =20 /* Check for negative values or invalid clocks */ if (unlikely((u32) clock >=3D MAX_CLOCKS)) - return -1; + return false; =20 if (IS_ENABLED(CONFIG_TIME_NS) && vc->clock_mode =3D=3D VDSO_CLOCKMODE_TIMENS) @@ -427,23 +427,25 @@ int __cvdso_clock_getres_common(const struct vdso_tim= e_data *vd, clockid_t clock */ ns =3D LOW_RES_NSEC; } else { - return -1; + return false; } =20 if (likely(res)) { res->tv_sec =3D 0; res->tv_nsec =3D ns; } - return 0; + return true; } =20 static __maybe_unused int __cvdso_clock_getres_data(const struct vdso_time_data *vd, clockid_t c= lock, struct __kernel_timespec *res) { - int ret =3D __cvdso_clock_getres_common(vd, clock, res); + bool ok; =20 - if (unlikely(ret)) + ok =3D __cvdso_clock_getres_common(vd, clock, res); + + if (unlikely(!ok)) return clock_getres_fallback(clock, res); return 0; } @@ -460,18 +462,18 @@ __cvdso_clock_getres_time32_data(const struct vdso_ti= me_data *vd, clockid_t cloc struct old_timespec32 *res) { struct __kernel_timespec ts; - int ret; + bool ok; =20 - ret =3D __cvdso_clock_getres_common(vd, clock, &ts); + ok =3D __cvdso_clock_getres_common(vd, clock, &ts); =20 - if (unlikely(ret)) + if (unlikely(!ok)) return clock_getres32_fallback(clock, res); =20 if (likely(res)) { res->tv_sec =3D ts.tv_sec; res->tv_nsec =3D ts.tv_nsec; } - return ret; + return 0; } =20 static __maybe_unused int --=20 2.50.0 From nobody Wed Oct 8 07:37:00 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11FD526D4D5; Tue, 1 Jul 2025 08:58:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360293; cv=none; b=R/CQf1z4wvm/rAIDVzDdm7Qbj3gK1z3uDs6EYz8ThC/hxI8/K/+MP7X2EMebRXuMybt20jK2wiNNQ1TS/5YGjqV3LK5CT9r4TVaYhYhuhRQPMnIDJkz4v9M9EQwLOucpxlnw1MwqD9KIgczGUowSrRQA3ki61NW9mFXgNYsIS8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360293; c=relaxed/simple; bh=hXHsnYDcoK6vZrSu6iAfWgcpr0RtJi0oTjs+lySQy+A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IDHFGaV6UUGKjh2SeavuWeUFPe7sL4Jdvhj9NaJHn5eR81m2MQxGqauF9CX4Ap0PsD/wgRa5BCV2+7ZzT2xSkhOrzwy5xanVmgVABjZD7DqCM9mmd9h9KEFkpYp+6OSIoIQ3gA5ZdGZb7+wzIBQrdPIGLXkRLXisHptB8YWpPfM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JOuClH5z; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JUWHL11Y; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JOuClH5z"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JUWHL11Y" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1751360288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cikZxWQJUp10v41R0BNtsJYkeVVYRn1u1TYcRTLvcoQ=; b=JOuClH5zQfirMyVQzHci+YfWykFkJQAT07wxXn8bnSfP4v2Mtf+khZO8PSEMtF5vyKm2kz r9Sikskh2A//wDpioSHNcdhBU907OkSp6RxyCqpFzG8qB/Y0Gnpyju4ax0/BBFlQIn7iV9 azZNnRv7uHbwqAQ/uzD8ey9XSnndaMTkvoPtMwxEJxmxnYJLXsfA5gLdbVNMaUJSdPldIZ wjjgeBdVsnfqK8THDT6DDv0sBNshupWmWDV+pchmGkAbCgjGLE4tDXdD1N5OYnFQEg4btp +DHxqtWX5GHGrBp6V60Y/Pdj4EitHMpYXPS1TM0+AuTM0vn2bZf2nTS/ZDR/9Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1751360288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cikZxWQJUp10v41R0BNtsJYkeVVYRn1u1TYcRTLvcoQ=; b=JUWHL11Y6dNQ7/wHtW7b8xlh7JM5awfSucplCUe0MFlcjzaQ9+fKPqu+fLeoBv4h/ZcJVx +HsBDFUhjK1wERAA== Date: Tue, 01 Jul 2025 10:58:00 +0200 Subject: [PATCH 06/14] vdso/gettimeofday: Return bool from clock_gettime() helpers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250701-vdso-auxclock-v1-6-df7d9f87b9b8@linutronix.de> References: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> In-Reply-To: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> To: Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Shuah Khan , Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Stephen Boyd , Catalin Marinas , Will Deacon , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, Richard Cochran , Christopher Hall , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , Kurt Kanzenbach , Nam Cao , Antoine Tenart , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1751360285; l=6489; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=hXHsnYDcoK6vZrSu6iAfWgcpr0RtJi0oTjs+lySQy+A=; b=HQ6guH4xKYzDLrGcPir6sQ0D8ksrjbFgWflXvOxV/zrvFpJHB21lBA59Vudl9gKnpFZ5XRa3n qIsPlaEK4LvA65HlAXaFwZAVlN+fBWsOzWip/2yX8Py+WUG7TeVh+S7 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The internal helpers are effectively using boolean results, while pretending to use error numbers. Switch the return type to bool for more clarity. Signed-off-by: Thomas Wei=C3=9Fschuh Tested-by: Mark Brown --- lib/vdso/gettimeofday.c | 58 +++++++++++++++++++++++++--------------------= ---- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c index 9b77f23566f6a35887d4c9aaefc61a971131b499..c5266532a097c06f33d12e345c6= 95357d75abf42 100644 --- a/lib/vdso/gettimeofday.c +++ b/lib/vdso/gettimeofday.c @@ -82,8 +82,8 @@ const struct vdso_time_data *__arch_get_vdso_u_timens_dat= a(const struct vdso_tim #endif /* CONFIG_GENERIC_VDSO_DATA_STORE */ =20 static __always_inline -int do_hres_timens(const struct vdso_time_data *vdns, const struct vdso_cl= ock *vcns, - clockid_t clk, struct __kernel_timespec *ts) +bool do_hres_timens(const struct vdso_time_data *vdns, const struct vdso_c= lock *vcns, + clockid_t clk, struct __kernel_timespec *ts) { const struct vdso_time_data *vd =3D __arch_get_vdso_u_timens_data(vdns); const struct timens_offset *offs =3D &vcns->offset[clk]; @@ -103,11 +103,11 @@ int do_hres_timens(const struct vdso_time_data *vdns,= const struct vdso_clock *v seq =3D vdso_read_begin(vc); =20 if (unlikely(!vdso_clocksource_ok(vc))) - return -1; + return false; =20 cycles =3D __arch_get_hw_counter(vc->clock_mode, vd); if (unlikely(!vdso_cycles_ok(cycles))) - return -1; + return false; ns =3D vdso_calc_ns(vc, cycles, vdso_ts->nsec); sec =3D vdso_ts->sec; } while (unlikely(vdso_read_retry(vc, seq))); @@ -123,7 +123,7 @@ int do_hres_timens(const struct vdso_time_data *vdns, c= onst struct vdso_clock *v ts->tv_sec =3D sec + __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); ts->tv_nsec =3D ns; =20 - return 0; + return true; } #else static __always_inline @@ -133,16 +133,16 @@ const struct vdso_time_data *__arch_get_vdso_u_timens= _data(const struct vdso_tim } =20 static __always_inline -int do_hres_timens(const struct vdso_time_data *vdns, const struct vdso_cl= ock *vcns, - clockid_t clk, struct __kernel_timespec *ts) +bool do_hres_timens(const struct vdso_time_data *vdns, const struct vdso_c= lock *vcns, + clockid_t clk, struct __kernel_timespec *ts) { - return -EINVAL; + return false; } #endif =20 static __always_inline -int do_hres(const struct vdso_time_data *vd, const struct vdso_clock *vc, - clockid_t clk, struct __kernel_timespec *ts) +bool do_hres(const struct vdso_time_data *vd, const struct vdso_clock *vc, + clockid_t clk, struct __kernel_timespec *ts) { const struct vdso_timestamp *vdso_ts =3D &vc->basetime[clk]; u64 cycles, sec, ns; @@ -150,7 +150,7 @@ int do_hres(const struct vdso_time_data *vd, const stru= ct vdso_clock *vc, =20 /* Allows to compile the high resolution parts out */ if (!__arch_vdso_hres_capable()) - return -1; + return false; =20 do { /* @@ -173,11 +173,11 @@ int do_hres(const struct vdso_time_data *vd, const st= ruct vdso_clock *vc, smp_rmb(); =20 if (unlikely(!vdso_clocksource_ok(vc))) - return -1; + return false; =20 cycles =3D __arch_get_hw_counter(vc->clock_mode, vd); if (unlikely(!vdso_cycles_ok(cycles))) - return -1; + return false; ns =3D vdso_calc_ns(vc, cycles, vdso_ts->nsec); sec =3D vdso_ts->sec; } while (unlikely(vdso_read_retry(vc, seq))); @@ -189,13 +189,13 @@ int do_hres(const struct vdso_time_data *vd, const st= ruct vdso_clock *vc, ts->tv_sec =3D sec + __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); ts->tv_nsec =3D ns; =20 - return 0; + return true; } =20 #ifdef CONFIG_TIME_NS static __always_inline -int do_coarse_timens(const struct vdso_time_data *vdns, const struct vdso_= clock *vcns, - clockid_t clk, struct __kernel_timespec *ts) +bool do_coarse_timens(const struct vdso_time_data *vdns, const struct vdso= _clock *vcns, + clockid_t clk, struct __kernel_timespec *ts) { const struct vdso_time_data *vd =3D __arch_get_vdso_u_timens_data(vdns); const struct timens_offset *offs =3D &vcns->offset[clk]; @@ -223,20 +223,20 @@ int do_coarse_timens(const struct vdso_time_data *vdn= s, const struct vdso_clock */ ts->tv_sec =3D sec + __iter_div_u64_rem(nsec, NSEC_PER_SEC, &nsec); ts->tv_nsec =3D nsec; - return 0; + return true; } #else static __always_inline -int do_coarse_timens(const struct vdso_time_data *vdns, const struct vdso_= clock *vcns, - clockid_t clk, struct __kernel_timespec *ts) +bool do_coarse_timens(const struct vdso_time_data *vdns, const struct vdso= _clock *vcns, + clockid_t clk, struct __kernel_timespec *ts) { - return -1; + return false; } #endif =20 static __always_inline -int do_coarse(const struct vdso_time_data *vd, const struct vdso_clock *vc, - clockid_t clk, struct __kernel_timespec *ts) +bool do_coarse(const struct vdso_time_data *vd, const struct vdso_clock *v= c, + clockid_t clk, struct __kernel_timespec *ts) { const struct vdso_timestamp *vdso_ts =3D &vc->basetime[clk]; u32 seq; @@ -258,10 +258,10 @@ int do_coarse(const struct vdso_time_data *vd, const = struct vdso_clock *vc, ts->tv_nsec =3D vdso_ts->nsec; } while (unlikely(vdso_read_retry(vc, seq))); =20 - return 0; + return true; } =20 -static __always_inline int +static __always_inline bool __cvdso_clock_gettime_common(const struct vdso_time_data *vd, clockid_t cl= ock, struct __kernel_timespec *ts) { @@ -270,7 +270,7 @@ __cvdso_clock_gettime_common(const struct vdso_time_dat= a *vd, clockid_t clock, =20 /* Check for negative values or invalid clocks */ if (unlikely((u32) clock >=3D MAX_CLOCKS)) - return -1; + return false; =20 /* * Convert the clockid to a bitmask and use it to check which @@ -284,7 +284,7 @@ __cvdso_clock_gettime_common(const struct vdso_time_dat= a *vd, clockid_t clock, else if (msk & VDSO_RAW) vc =3D &vc[CS_RAW]; else - return -1; + return false; =20 return do_hres(vd, vc, clock, ts); } @@ -293,9 +293,11 @@ static __maybe_unused int __cvdso_clock_gettime_data(const struct vdso_time_data *vd, clockid_t cloc= k, struct __kernel_timespec *ts) { - int ret =3D __cvdso_clock_gettime_common(vd, clock, ts); + bool ok; =20 - if (unlikely(ret)) + ok =3D __cvdso_clock_gettime_common(vd, clock, ts); + + if (unlikely(!ok)) return clock_gettime_fallback(clock, ts); return 0; } --=20 2.50.0 From nobody Wed Oct 8 07:37:00 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E91F26D4EB; Tue, 1 Jul 2025 08:58:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360293; cv=none; b=poE1eVnr5ffYxd+fwJJfvLYTuFsiiAQNPeHaOUSN8varjZH975h0HtfheqNyhSloRCTpEW0TsIW+3qug2aMGgWMSZe2YO7iefHVo5mxjH+Q10AJk+7/sywEo7MV0Ky/j5PyYL718Thchk347JmA2ty99hcQGwC4dsgecQV9yBZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360293; c=relaxed/simple; bh=dRtOLc0Ah0kuXXHJncEp4KlW6Rn2+hYOmoEn9rpo9FQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=N85NzJoW2HRLmO2bG32DywmK9GUKQj6XRmf8EGmPIf3qgLIYRuhu2FqrgvOWyov4X4j/XuPUYAPnDMPOu6ePnkECE37SzeARZl2JgyBhi/8lqB2EP98G6tF+O2PXUtuYMf2BULCSCtUqHD7NoUHqOMY0TBUTwiwUmNes0sysOQI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hCdg9J/c; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=SODPMp3s; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hCdg9J/c"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="SODPMp3s" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1751360289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xLGlXBLoHCl8iTZFGkpWl+4cLC4fbRbFQ1Cna6OA294=; b=hCdg9J/c9E6RT0wp6/DhGRc8l2ths+F2e0C3PVLM5LyMtcRgzSnaJkHkcQPPghkg/XeIpd LWGQ7lX3WJUFxu3ek2BvL8C6SIKdZZCnnfAazdnoDGestgjVmLWS7pp8l9vtfnfLKRJCbr XJXluEsSZP/mJ3JhmR2CxKsF1IugmZxvxhTTY235Ij3lq6ld4ULlPsfC9olhKlyxHYgWTC NEb5IBp538bTUXHNDpo7FJPd/m1D4oK/x4gPmt5lejA0NpMusHSEhEYSIkfUR9IhQqKnXh /5nUYmD7mc2ugRKGfjNgNfpa0roYwNLQgrs/CeQU6Hcca6RY3aKTm6HfPSUclw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1751360289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xLGlXBLoHCl8iTZFGkpWl+4cLC4fbRbFQ1Cna6OA294=; b=SODPMp3s/oAwW35AK1TnWm29pKng8GpRaNdGr9v2vbfuSLyfCFSWsbW6EBxgbSwh5NqAtV LeWbBp4VXN/84xCw== Date: Tue, 01 Jul 2025 10:58:01 +0200 Subject: [PATCH 07/14] vdso/gettimeofday: Introduce vdso_clockid_valid() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250701-vdso-auxclock-v1-7-df7d9f87b9b8@linutronix.de> References: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> In-Reply-To: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> To: Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Shuah Khan , Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Stephen Boyd , Catalin Marinas , Will Deacon , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, Richard Cochran , Christopher Hall , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , Kurt Kanzenbach , Nam Cao , Antoine Tenart , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1751360285; l=1538; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=dRtOLc0Ah0kuXXHJncEp4KlW6Rn2+hYOmoEn9rpo9FQ=; b=HTm3jtAk7vagm4p603uxzJ6EQojuf/6O5qSR9JWQUCAE793nMRMynN0XVRWXyboEG1fCIAwoE 4hpXQVIhcWLCO71c9GbNNfwf5IiU8zNqmXABKY3tM0pBQK7mnBSSfn1 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= With the upcoming addition of auxiliary clocks the clockid validation will become more complicated. Split it into a dedicated function to keep the code readable. Signed-off-by: Thomas Wei=C3=9Fschuh --- lib/vdso/gettimeofday.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c index c5266532a097c06f33d12e345c695357d75abf42..215151bd5a1320ee6edda8f334d= 47c739577f696 100644 --- a/lib/vdso/gettimeofday.c +++ b/lib/vdso/gettimeofday.c @@ -71,6 +71,12 @@ static inline bool vdso_cycles_ok(u64 cycles) } #endif =20 +static __always_inline bool vdso_clockid_valid(clockid_t clock) +{ + /* Check for negative values or invalid clocks */ + return likely((u32) clock < MAX_CLOCKS); +} + #ifdef CONFIG_TIME_NS =20 #ifdef CONFIG_GENERIC_VDSO_DATA_STORE @@ -268,8 +274,7 @@ __cvdso_clock_gettime_common(const struct vdso_time_dat= a *vd, clockid_t clock, const struct vdso_clock *vc =3D vd->clock_data; u32 msk; =20 - /* Check for negative values or invalid clocks */ - if (unlikely((u32) clock >=3D MAX_CLOCKS)) + if (!vdso_clockid_valid(clock)) return false; =20 /* @@ -405,8 +410,7 @@ bool __cvdso_clock_getres_common(const struct vdso_time= _data *vd, clockid_t cloc u32 msk; u64 ns; =20 - /* Check for negative values or invalid clocks */ - if (unlikely((u32) clock >=3D MAX_CLOCKS)) + if (!vdso_clockid_valid(clock)) return false; =20 if (IS_ENABLED(CONFIG_TIME_NS) && --=20 2.50.0 From nobody Wed Oct 8 07:37:00 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B529D26B09A; Tue, 1 Jul 2025 08:58:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360293; cv=none; b=K1tlUSGldgTxZpSYQezJmH9ImcUO8tQ569ZJz+CUuEY12heee+R71EgBu8kcnKT6yUDSZOVpFcdX0jXO2edXi0Q8OK3QUbTxyyCbgEFlLj0gnICxmMkXzwQ+oKq8SpbOwcUKLyWH9THNqPtg6z4AvJzi04Kqn1SzK/swSqJ697Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360293; c=relaxed/simple; bh=CC5cQSfSGmKdKkeZa7p5tvupyfG2CLNGehREDf1mFcc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OHTF7f41mTwowO9YT0QktMOdR1R4Qc2iEd+ZugYFMeDh6hPSm13WDoyOOBtYuWA2mNa0pNCxhEHeT/Ysbp1rZKMv7qQtWEmnu2b5GBCqH0OCkYB/D/WGXX9Fci1idZXLsYGagL7XHgfVGeNWuzOYqs8KXAz+iFbTDrN15gNij5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wB37phIU; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ZgZmCR6h; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wB37phIU"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ZgZmCR6h" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1751360289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VUv1tHn4Gb15SCtBOdwANRio4D/S8/QmhpZlRN18zW8=; b=wB37phIU1cgHL9oe4WYfMGliy5jbaoTzF0DhUFJs/rOu6Z9k1d3vYlAoN9EKggIwQUdu7l +TljAEBva1iFEhXtwj719UDDhlB7E7ALl8cwsgv8F+HUkIarv/qpDzLbPy7v4o/GeFoOFd 2R4a1ZFq2m8qwljdwSfFlnkniHuUtcqgGxU+sUvfvGw1lpcFjL8gkz81eCl3e1b7Pk8VKb 10dcpeqesAIzny9jyLb46PnxK5K9QIJu7XVW1XaC7Hw+NAvENeYfSx+DUhGLnd9jyQJXPU ot0rpxGS270Y+z4vxiKynztpNbEmcLdOyJkwgdvYSvWmLEQ/LGbCnC4ntsmYTA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1751360289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VUv1tHn4Gb15SCtBOdwANRio4D/S8/QmhpZlRN18zW8=; b=ZgZmCR6hsNO6h+aAy42Sjmgm6zIioVVD4G5orMl9SniBw8do+p9kwhp5Mrhd+6o7spFRYw zppOqtmG7rk7GaCA== Date: Tue, 01 Jul 2025 10:58:02 +0200 Subject: [PATCH 08/14] vdso/gettimeofday: Introduce vdso_set_timespec() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250701-vdso-auxclock-v1-8-df7d9f87b9b8@linutronix.de> References: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> In-Reply-To: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> To: Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Shuah Khan , Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Stephen Boyd , Catalin Marinas , Will Deacon , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, Richard Cochran , Christopher Hall , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , Kurt Kanzenbach , Nam Cao , Antoine Tenart , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1751360285; l=2428; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=CC5cQSfSGmKdKkeZa7p5tvupyfG2CLNGehREDf1mFcc=; b=7doTRp//wkLzPlGHPeeVXsRB2rVPSQaX9szW5pOx13TUBMCDQh6Ba5Lm0uy/yEitK/NoNivtP C/e1SD9At+pB4f04mSGvpQui1WuaofZ+BHAxek5oRzMozDtD+tqbaLD X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= This code is duplicated and with the introduction of auxiliary clocks will be duplicated even more. Introduce a helper. Signed-off-by: Thomas Wei=C3=9Fschuh --- lib/vdso/gettimeofday.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c index 215151bd5a1320ee6edda8f334d47c739577f696..50611ba28abfcfc7841616e8787= 101ea1ffcb7d8 100644 --- a/lib/vdso/gettimeofday.c +++ b/lib/vdso/gettimeofday.c @@ -77,6 +77,16 @@ static __always_inline bool vdso_clockid_valid(clockid_t= clock) return likely((u32) clock < MAX_CLOCKS); } =20 +/* + * Must not be invoked within the sequence read section as a race inside + * that loop could result in __iter_div_u64_rem() being extremely slow. + */ +static __always_inline void vdso_set_timespec(struct __kernel_timespec *ts= , u64 sec, u64 ns) +{ + ts->tv_sec =3D sec + __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); + ts->tv_nsec =3D ns; +} + #ifdef CONFIG_TIME_NS =20 #ifdef CONFIG_GENERIC_VDSO_DATA_STORE @@ -122,12 +132,7 @@ bool do_hres_timens(const struct vdso_time_data *vdns,= const struct vdso_clock * sec +=3D offs->sec; ns +=3D offs->nsec; =20 - /* - * Do this outside the loop: a race inside the loop could result - * in __iter_div_u64_rem() being extremely slow. - */ - ts->tv_sec =3D sec + __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); - ts->tv_nsec =3D ns; + vdso_set_timespec(ts, sec, ns); =20 return true; } @@ -188,12 +193,7 @@ bool do_hres(const struct vdso_time_data *vd, const st= ruct vdso_clock *vc, sec =3D vdso_ts->sec; } while (unlikely(vdso_read_retry(vc, seq))); =20 - /* - * Do this outside the loop: a race inside the loop could result - * in __iter_div_u64_rem() being extremely slow. - */ - ts->tv_sec =3D sec + __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); - ts->tv_nsec =3D ns; + vdso_set_timespec(ts, sec, ns); =20 return true; } @@ -223,12 +223,8 @@ bool do_coarse_timens(const struct vdso_time_data *vdn= s, const struct vdso_clock sec +=3D offs->sec; nsec +=3D offs->nsec; =20 - /* - * Do this outside the loop: a race inside the loop could result - * in __iter_div_u64_rem() being extremely slow. - */ - ts->tv_sec =3D sec + __iter_div_u64_rem(nsec, NSEC_PER_SEC, &nsec); - ts->tv_nsec =3D nsec; + vdso_set_timespec(ts, sec, nsec); + return true; } #else --=20 2.50.0 From nobody Wed Oct 8 07:37:00 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67709270EC5; Tue, 1 Jul 2025 08:58:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360294; cv=none; b=SpTfuAiNB8p+3fXbpLoHk2mkZ+DlNnwf8DH8gMqiGe0OVqUKF3kJOaKyT4zCkgOJNnXl8fohfKCspxzYKrThX002jHUF31Of3gD7aS/gGSfmdpiGcaOIm4aKIsshOLUseKStWgwQ8geRzlT05KHXQgrzYRE6+qi93CEBGbhGTZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360294; c=relaxed/simple; bh=0gcdrnEsMPGXM7V1cQMwcYqk1YZH4nLzPxPwfGW0xR8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b0UpsKZWRsx8jzADzOCkKoRpzthScC5VSxHwglhigtRNNZS3mnYkNKeCfXm2I3zCHJoNUfOSuq4HuDpyU3t8TXK6nb0IwMw3v+BO+AdC8ZlfUFS/2UsmAnJlPpwUqb+ynLxsghEZxoIVX34KSsRWzQt3dGg70Zizrqd2cS+Gfz8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bYXsA4Vm; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=FUAZLmGC; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bYXsA4Vm"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="FUAZLmGC" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1751360290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ppCsL5OVpZ0yuAtg6csvrRyWQ6LdTuXSpwMAtwV+V0Y=; b=bYXsA4VmsKOFmUrNashY+TPxEK36HHs4Y1/tS2ESFs1Sa90DCYM6pLwrbgoJjLO9Yshy+E cdk0CYyPuvhpLBR7Y0A+DlWZQHPQSlGG/J9v8CDbIplQiFtQfl69euvkbceuSZ6/gOyv3D LeqjJBv/x3eKsgi35z8qXD7dUsYUyRboPPfq07V+n5/u6MPqzpLvTOYNTzjaMkCWOOV3FK 4wCX5/sLqv0t1UbLTMX6VPn6Is9LA1QB4JKytwxEP2A1fYNXPlqbsEVBOA58ednTEaW66I XC1RZs82INjio8hSj3u0el7uaWbzFkkzJ74lx5EDuRzdsUVXaXe8E9i1wked1A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1751360290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ppCsL5OVpZ0yuAtg6csvrRyWQ6LdTuXSpwMAtwV+V0Y=; b=FUAZLmGC+2tmC8OKCBX9MqhPAG/d2/zbiiyE0dF93F/Iph1Ozm1GlEk02gT6NQSgN4PusN jI73TlfCOkkGPbCg== Date: Tue, 01 Jul 2025 10:58:03 +0200 Subject: [PATCH 09/14] vdso/gettimeofday: Introduce vdso_get_timestamp() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250701-vdso-auxclock-v1-9-df7d9f87b9b8@linutronix.de> References: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> In-Reply-To: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> To: Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Shuah Khan , Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Stephen Boyd , Catalin Marinas , Will Deacon , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, Richard Cochran , Christopher Hall , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , Kurt Kanzenbach , Nam Cao , Antoine Tenart , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1751360285; l=3113; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=0gcdrnEsMPGXM7V1cQMwcYqk1YZH4nLzPxPwfGW0xR8=; b=IVyUepdPhAMRvqhjIat4Jqx5hEP07rmKNZAocQkuDF92onJqNyNB/RxoxLX8R4u71m9CiGGyF mM3B4kOZaFfA1deox2uLdBFZiKv83hAOc9ObMZimXUM26NGMOQTuH9L X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= This code is duplicated and with the introduction of auxiliary clocks will be duplicated even more. Introduce a helper. Signed-off-by: Thomas Wei=C3=9Fschuh --- lib/vdso/gettimeofday.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c index 50611ba28abfcfc7841616e8787101ea1ffcb7d8..c383878bb5445a62d8fea6591e8= 550183852c2e6 100644 --- a/lib/vdso/gettimeofday.c +++ b/lib/vdso/gettimeofday.c @@ -87,6 +87,26 @@ static __always_inline void vdso_set_timespec(struct __k= ernel_timespec *ts, u64 ts->tv_nsec =3D ns; } =20 +static __always_inline +bool vdso_get_timestamp(const struct vdso_time_data *vd, const struct vdso= _clock *vc, + unsigned int clkidx, u64 *sec, u64 *ns) +{ + const struct vdso_timestamp *vdso_ts =3D &vc->basetime[clkidx]; + u64 cycles; + + if (unlikely(!vdso_clocksource_ok(vc))) + return false; + + cycles =3D __arch_get_hw_counter(vc->clock_mode, vd); + if (unlikely(!vdso_cycles_ok(cycles))) + return false; + + *ns =3D vdso_calc_ns(vc, cycles, vdso_ts->nsec); + *sec =3D vdso_ts->sec; + + return true; +} + #ifdef CONFIG_TIME_NS =20 #ifdef CONFIG_GENERIC_VDSO_DATA_STORE @@ -104,28 +124,20 @@ bool do_hres_timens(const struct vdso_time_data *vdns= , const struct vdso_clock * const struct vdso_time_data *vd =3D __arch_get_vdso_u_timens_data(vdns); const struct timens_offset *offs =3D &vcns->offset[clk]; const struct vdso_clock *vc =3D vd->clock_data; - const struct vdso_timestamp *vdso_ts; - u64 cycles, ns; u32 seq; s64 sec; + u64 ns; =20 if (clk !=3D CLOCK_MONOTONIC_RAW) vc =3D &vc[CS_HRES_COARSE]; else vc =3D &vc[CS_RAW]; - vdso_ts =3D &vc->basetime[clk]; =20 do { seq =3D vdso_read_begin(vc); =20 - if (unlikely(!vdso_clocksource_ok(vc))) - return false; - - cycles =3D __arch_get_hw_counter(vc->clock_mode, vd); - if (unlikely(!vdso_cycles_ok(cycles))) + if (!vdso_get_timestamp(vd, vc, clk, &sec, &ns)) return false; - ns =3D vdso_calc_ns(vc, cycles, vdso_ts->nsec); - sec =3D vdso_ts->sec; } while (unlikely(vdso_read_retry(vc, seq))); =20 /* Add the namespace offset */ @@ -155,8 +167,7 @@ static __always_inline bool do_hres(const struct vdso_time_data *vd, const struct vdso_clock *vc, clockid_t clk, struct __kernel_timespec *ts) { - const struct vdso_timestamp *vdso_ts =3D &vc->basetime[clk]; - u64 cycles, sec, ns; + u64 sec, ns; u32 seq; =20 /* Allows to compile the high resolution parts out */ @@ -183,14 +194,8 @@ bool do_hres(const struct vdso_time_data *vd, const st= ruct vdso_clock *vc, } smp_rmb(); =20 - if (unlikely(!vdso_clocksource_ok(vc))) + if (!vdso_get_timestamp(vd, vc, clk, &sec, &ns)) return false; - - cycles =3D __arch_get_hw_counter(vc->clock_mode, vd); - if (unlikely(!vdso_cycles_ok(cycles))) - return false; - ns =3D vdso_calc_ns(vc, cycles, vdso_ts->nsec); - sec =3D vdso_ts->sec; } while (unlikely(vdso_read_retry(vc, seq))); =20 vdso_set_timespec(ts, sec, ns); --=20 2.50.0 From nobody Wed Oct 8 07:37:00 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6920C270EC8; Tue, 1 Jul 2025 08:58:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360294; cv=none; b=aaco+A6DDZue1PGrAUCtja42Ighu5nLowswydKhNXKkIf+/bvdUCvHVJT5KVEjqcaU2Hb+H2QWr92lVFwuGIfxcQDxOqa9O8OGASVL47yBOteA03+Gih/sd25+1neqE7/1xvOTQ7R23cUDpVPHo4OQU8vkZJSCb6HXE8t0qBf6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360294; c=relaxed/simple; bh=QLkkveUI/cyGTLTyApgh10OSDNXJ3sXYct42yO3P5B0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nBjSgUIUCYtdMbKgIb9+tNXSHZrJQlqkS904XRHrNTpUOn1eFanhXIIsBG6t6JzLpuhxgCjMrhk710YggIBFEF/U5Rq31lQgMRMwK9P8Rev+wrdXq4iFUp0knKqJPuo1kwu6SK31hGuX4m0yHfyUFposqzGfaLaXlqo6burvXvY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=OU0d6ovJ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=+OMgzfx8; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="OU0d6ovJ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="+OMgzfx8" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1751360291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j01uzCoLVpnyze/ne4qVPEjweSMhaL+T/SfXMybPgVw=; b=OU0d6ovJHnj+NG7timt9a2g47DdM/l6V8vNHRRCHU0tb2nmj/mxJLvc2WYicLFE0dYHx7E hwPYnSCtm/lV/4RiGCJHaWu6Cvb2TR9CqYkIzIH4m+vQlgJl2BSB0nbKOCIVejdj8KCGzT da+KlCNMsDAnY4ewAstftHZm7IeEIcHicbgF9R82bzPFPI5w4TxW1CAp4Vtt8m3JQZr+yg m4LvZUNysPiTG4yFHMkx2hmmbKPygkdOQWpw8UkDPJJ2MetJ4TAJFWGIPqPtaQ0Y5YDc4j blyqDuE3T54WX9MieaB2vFTe+3n+dyNIgYzbdEV6Q/y/teG8kXStt47xlurMOA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1751360291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j01uzCoLVpnyze/ne4qVPEjweSMhaL+T/SfXMybPgVw=; b=+OMgzfx8O8M8wqez+hCXg6yGhzfqiC+uJQrKAjMfTNDAfi78MoMpEL6m55UMJRKP2MKUdH 9mEWAnKVmsqUGUBA== Date: Tue, 01 Jul 2025 10:58:04 +0200 Subject: [PATCH 10/14] vdso: Introduce aux_clock_resolution_ns() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250701-vdso-auxclock-v1-10-df7d9f87b9b8@linutronix.de> References: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> In-Reply-To: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> To: Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Shuah Khan , Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Stephen Boyd , Catalin Marinas , Will Deacon , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, Richard Cochran , Christopher Hall , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , Kurt Kanzenbach , Nam Cao , Antoine Tenart , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1751360285; l=1617; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=QLkkveUI/cyGTLTyApgh10OSDNXJ3sXYct42yO3P5B0=; b=R8Ek6dz1meGMCadr7lA0G0xaOobq5oTQx63iTTSrhy6xilDGAYn7vlT45j/KMLSiBBuaePOs8 f+1StZD0FpkDR8PTXaqwnWJ5w40lEfFP0WlKydEOKc/miaPfb697wmm X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Move the constant resolution to a shared header, so the vDSO can use it and return it without going through a syscall. Signed-off-by: Thomas Wei=C3=9Fschuh --- include/vdso/auxclock.h | 13 +++++++++++++ kernel/time/timekeeping.c | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/vdso/auxclock.h b/include/vdso/auxclock.h new file mode 100644 index 0000000000000000000000000000000000000000..6d6e74cbc400e7f5cd719428075= 9f5e5f3059900 --- /dev/null +++ b/include/vdso/auxclock.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _VDSO_AUXCLOCK_H +#define _VDSO_AUXCLOCK_H + +#include +#include + +static __always_inline u64 aux_clock_resolution_ns(void) +{ + return 1; +} + +#endif /* _VDSO_AUXCLOCK_H */ diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 6a61887eb87e364b3ef170939919a8d4046c0508..6a088378df54d561ecfeafb45a8= b54333e11a9a7 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -26,6 +26,8 @@ #include #include =20 +#include + #include "tick-internal.h" #include "ntp_internal.h" #include "timekeeping_internal.h" @@ -2842,8 +2844,8 @@ static int aux_get_res(clockid_t id, struct timespec6= 4 *tp) if (!clockid_aux_valid(id)) return -ENODEV; =20 - tp->tv_sec =3D 0; - tp->tv_nsec =3D 1; + tp->tv_sec =3D aux_clock_resolution_ns() / NSEC_PER_SEC; + tp->tv_nsec =3D aux_clock_resolution_ns() % NSEC_PER_SEC; return 0; } =20 --=20 2.50.0 From nobody Wed Oct 8 07:37:00 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EF0C271455; Tue, 1 Jul 2025 08:58:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360295; cv=none; b=YVN66J4zch5TqcnBYrjpfIEFLEK617yfQ8JHAf0FuwrdYvstHg8U0T0RaWpQJnE3hjBGrChcysZ2aredc+azUpeqh7DjHBQ1go3w0/8ghXhTui6FM/w4hOR4RYhFe5O36lPDMi2+9aH/z7J0hbtJIy26P4BTF7QcXaWAwfTbgi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360295; c=relaxed/simple; bh=I8cM041g5IAfoTDOmdmJralm5nAWrjZh5d0Wh6I7fg8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gVbL7j5FmsLVlpEYSv7UEV0LPr77l60LaZfVGJu6XjNgxNhbCwsAIY6zaGb6o3jxHohYOuw688/SUNR9lTDIsmQRuAWLhjznG7hOt0RgthbEOFsBJvRMBFwKJuizojifmPbIPpGxiO36dm3PZQdiQOYUigwyPi2KuWimWvvLYkI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=zmRoiz5O; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Nwg3GIkA; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zmRoiz5O"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Nwg3GIkA" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1751360291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M/qdmfV5C2ezGfUpUoaRbfT+DGO6POVIJmN8LgdDLsU=; b=zmRoiz5OMdwJSV5VU8x1H6fNophfk3dzw3fhf+q24KXhEmzotP9HrGiMxOyBY1ltOm6tTb jHcbiVfVn+1srnp0XnEEhuT8CnRw3cXknGmyeDz5pXVNl9nAitQ8a1FJmu2TMSjk8aQP1u sGlEvU8hqYj9zgc7ju+Mmc1aeSPz3E+bI/8WvFlejxHUOZTzfN9QzlAeJO5Elc85MlBiMK ulwAkv0btp0LvdpG0MYPiu5i0Q6kzKBs+U5k8D5Ofvga8GvdgHKFhsxfTDzUOHJ2GfioWy tRuJrnl0sQ8qAdcD1kjAgoDPnqFN+Hiq58XMzh/yR016RT1TvbZgdpeWE5SLPg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1751360291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M/qdmfV5C2ezGfUpUoaRbfT+DGO6POVIJmN8LgdDLsU=; b=Nwg3GIkAH3MhBIPzrgaFS0OydPjn2AynWmyN+Z2lnAQT8npLekXRFGfCyAe+zoobFGy+zd upSbSMuKVw4YbqCA== Date: Tue, 01 Jul 2025 10:58:05 +0200 Subject: [PATCH 11/14] vdso/vsyscall: Update auxiliary clock data in the datapage Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250701-vdso-auxclock-v1-11-df7d9f87b9b8@linutronix.de> References: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> In-Reply-To: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> To: Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Shuah Khan , Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Stephen Boyd , Catalin Marinas , Will Deacon , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, Richard Cochran , Christopher Hall , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , Kurt Kanzenbach , Nam Cao , Antoine Tenart , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1751360285; l=5571; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=I8cM041g5IAfoTDOmdmJralm5nAWrjZh5d0Wh6I7fg8=; b=ngNkB8/T/+ReUqwzpn1ZvYgZ8QeREdu0ojU91hJIArod5pUxq3LYeNFeie2plEmtNdpep3Eg7 Sglv31wh+OcD/YbyBW/WgPBOoXr7sUtD0Yy5RIV30x+PWBoPWTBvtVs X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Expose the auxiliary clock data so it can be read from the vDSO. Architectures not using the generic vDSO time framework, namely SPARC64, are not supported. Signed-off-by: Thomas Wei=C3=9Fschuh --- include/linux/timekeeper_internal.h | 13 ++++++++++++ include/vdso/datapage.h | 3 +++ kernel/time/namespace.c | 5 +++++ kernel/time/timekeeping.c | 12 +++++++++++ kernel/time/vsyscall.c | 40 +++++++++++++++++++++++++++++++++= ++++ 5 files changed, 73 insertions(+) diff --git a/include/linux/timekeeper_internal.h b/include/linux/timekeeper= _internal.h index ca79938b62f396afd503e0cf06bbecf6f95cfce4..5de2e019399c72246f7d7dfad56= 1c8b3d479dbd1 100644 --- a/include/linux/timekeeper_internal.h +++ b/include/linux/timekeeper_internal.h @@ -190,4 +190,17 @@ static inline void update_vsyscall_tz(void) } #endif =20 +#if defined(CONFIG_GENERIC_TIME_VSYSCALL) && defined(CONFIG_GENERIC_GETTIM= EOFDAY) && \ + defined(CONFIG_POSIX_AUX_CLOCKS) + +extern void vdso_time_update_aux(struct timekeeper *tk); + +#else + +static inline void vdso_time_update_aux(struct timekeeper *tk) +{ +} + +#endif /* CONFIG_GENERIC_TIME_VSYSCALL && CONFIG_POSIX_AUX_CLOCKS */ + #endif /* _LINUX_TIMEKEEPER_INTERNAL_H */ diff --git a/include/vdso/datapage.h b/include/vdso/datapage.h index 1864e76e8f691bab10813543880f71bc59afa9c0..f4c96d9ce674abb07ccd8703f1a= 04da7631c1677 100644 --- a/include/vdso/datapage.h +++ b/include/vdso/datapage.h @@ -38,6 +38,7 @@ struct vdso_arch_data { #endif =20 #define VDSO_BASES (CLOCK_TAI + 1) +#define VDSO_BASE_AUX 0 #define VDSO_HRES (BIT(CLOCK_REALTIME) | \ BIT(CLOCK_MONOTONIC) | \ BIT(CLOCK_BOOTTIME) | \ @@ -117,6 +118,7 @@ struct vdso_clock { * @arch_data: architecture specific data (optional, defaults * to an empty struct) * @clock_data: clocksource related data (array) + * @aux_clock_data: auxiliary clocksource related data (array) * @tz_minuteswest: minutes west of Greenwich * @tz_dsttime: type of DST correction * @hrtimer_res: hrtimer resolution @@ -133,6 +135,7 @@ struct vdso_time_data { struct arch_vdso_time_data arch_data; =20 struct vdso_clock clock_data[CS_BASES]; + struct vdso_clock aux_clock_data[MAX_AUX_CLOCKS]; =20 s32 tz_minuteswest; s32 tz_dsttime; diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c index e3642278df433c41654ffb6a8043c3fcecc2994a..667452768ed3b50e48e3cfb70f8= ef68e4bed9e0b 100644 --- a/kernel/time/namespace.c +++ b/kernel/time/namespace.c @@ -242,6 +242,11 @@ static void timens_set_vvar_page(struct task_struct *t= ask, for (i =3D 0; i < CS_BASES; i++) timens_setup_vdso_clock_data(&vc[i], ns); =20 + if (IS_ENABLED(CONFIG_POSIX_AUX_CLOCKS)) { + for (i =3D 0; i < ARRAY_SIZE(vdata->aux_clock_data); i++) + timens_setup_vdso_clock_data(&vdata->aux_clock_data[i], ns); + } + out: mutex_unlock(&offset_lock); } diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 6a088378df54d561ecfeafb45a8b54333e11a9a7..928b8e0773f9e1b8fd700f130a7= 00c5908fe6c27 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -66,11 +66,21 @@ static inline bool tk_get_aux_ts64(unsigned int tkid, s= truct timespec64 *ts) { return ktime_get_aux_ts64(CLOCK_AUX + tkid - TIMEKEEPER_AUX_FIRST, ts); } + +static inline bool tk_is_aux(const struct timekeeper *tk) +{ + return tk->id >=3D TIMEKEEPER_AUX_FIRST && tk->id <=3D TIMEKEEPER_AUX_LAS= T; +} #else static inline bool tk_get_aux_ts64(unsigned int tkid, struct timespec64 *t= s) { return false; } + +static inline bool tk_is_aux(const struct timekeeper *tk) +{ + return false; +} #endif =20 /* flag for if timekeeping is suspended */ @@ -719,6 +729,8 @@ static void timekeeping_update_from_shadow(struct tk_da= ta *tkd, unsigned int act =20 update_fast_timekeeper(&tk->tkr_mono, &tk_fast_mono); update_fast_timekeeper(&tk->tkr_raw, &tk_fast_raw); + } else if (tk_is_aux(tk)) { + vdso_time_update_aux(tk); } =20 if (action & TK_CLOCK_WAS_SET) diff --git a/kernel/time/vsyscall.c b/kernel/time/vsyscall.c index df6bada2d58ed9a03e5dd3cb4b218983089a2877..62d9701db9135ba4ef377f3f534= a9279d7922d2d 100644 --- a/kernel/time/vsyscall.c +++ b/kernel/time/vsyscall.c @@ -136,6 +136,46 @@ void update_vsyscall_tz(void) __arch_sync_vdso_time_data(vdata); } =20 +#ifdef CONFIG_POSIX_AUX_CLOCKS +void vdso_time_update_aux(struct timekeeper *tk) +{ + struct vdso_time_data *vdata =3D vdso_k_time_data; + struct vdso_timestamp *vdso_ts; + struct vdso_clock *vc; + s32 clock_mode; + u64 nsec; + + vc =3D &vdata->aux_clock_data[tk->id - TIMEKEEPER_AUX_FIRST]; + vdso_ts =3D &vc->basetime[VDSO_BASE_AUX]; + clock_mode =3D tk->tkr_mono.clock->vdso_clock_mode; + if (!tk->clock_valid) + clock_mode =3D VDSO_CLOCKMODE_NONE; + + /* copy vsyscall data */ + vdso_write_begin_clock(vc, true); + + vc->clock_mode =3D clock_mode; + + if (clock_mode !=3D VDSO_CLOCKMODE_NONE) { + fill_clock_configuration(vc, &tk->tkr_mono); + + vdso_ts->sec =3D tk->xtime_sec; + + nsec =3D tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift; + nsec +=3D tk->offs_aux; + vdso_ts->sec +=3D __iter_div_u64_rem(nsec, NSEC_PER_SEC, &nsec); + nsec =3D nsec << tk->tkr_mono.shift; + vdso_ts->nsec =3D nsec; + } + + __arch_update_vdso_clock(vc); + + vdso_write_end_clock(vc, true); + + __arch_sync_vdso_time_data(vdata); +} +#endif + /** * vdso_update_begin - Start of a VDSO update section * --=20 2.50.0 From nobody Wed Oct 8 07:37:00 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 737BB27146E; Tue, 1 Jul 2025 08:58:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360295; cv=none; b=VovO7gw8XJ7H7LYELZBChMB4AxqQg31oZnFklh8h15sYHuZLEGZnYw9QuouMYz8dwAk+f7IwcwL/rKVO2eJwBISRQzL9XWzL7Ok8awQiYKmmGApmB/75+w9HYa16CrqJqUGhKkSIa2FfvT2+8USRavwejCPVVEYIdqk5h3kpH8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360295; c=relaxed/simple; bh=xvjCYJ8mK4mm1osuZA69etc3l9N5nef3XUciIrrNCVc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pBvJvJQ91r8bYoKjORNXSWcK7FWZhN4BbJEd0x/wLotIYWUoJowtJrcCAm1GqtHuLjFB/pX2qORHuZgDRILH5Swpc+hXmEvPOtFtQM2oSaHQp7Uu+FvqJxTVC6yokRGUVKEbqByh69FA/0IhPuGAPgQC/PKQWb/f4On6qpxREII= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cZUEI+ZW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ffbGYJYD; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cZUEI+ZW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ffbGYJYD" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1751360291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VRHvw41rR6k2CXfRNpVAkucpo+CGu/QUxPMlHxm0VFU=; b=cZUEI+ZWwrpIOUwpN59qkqfsHQ28OiVuU20/SMtS2hxUrw8aWnINnJ0ffpbNYHLJ/5UJXJ O/l6oUKRcdkWhfG41or2qOviq0jHjuXie8qblg4VoLc9NaI9eReM2nX4eb78wwJ40e3oZN YCDcbVu7zPg8Hl08XKGxNbwDDSxHz/1sU41hCYsUpiCxx+eV59bW8Rhsi8M8rWHsJsRJpC imw3KijpfVGsKmTdNRMY79NJo1mF9+RLw3BEMKAkbmkj1/WPaVhkAglbZf0DksmoveWuo1 LH/hOXnMAjs6m6v4kTTHgTb5Z6U6IUh0NBzI/pT0NUgzc+orqQPhJCo5izyYUg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1751360291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VRHvw41rR6k2CXfRNpVAkucpo+CGu/QUxPMlHxm0VFU=; b=ffbGYJYDgaQ3PocT43ygu+WEgcKUBnnhJ5s7syxm20zKVw/z/N3DLGAS7Q2fBccv1uQ+JB cJWrBrHgywPHeeBw== Date: Tue, 01 Jul 2025 10:58:06 +0200 Subject: [PATCH 12/14] vdso/gettimeofday: Add support for auxiliary clocks Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250701-vdso-auxclock-v1-12-df7d9f87b9b8@linutronix.de> References: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> In-Reply-To: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> To: Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Shuah Khan , Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Stephen Boyd , Catalin Marinas , Will Deacon , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, Richard Cochran , Christopher Hall , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , Kurt Kanzenbach , Nam Cao , Antoine Tenart , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1751360285; l=3709; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=xvjCYJ8mK4mm1osuZA69etc3l9N5nef3XUciIrrNCVc=; b=8epmu6riVb6Cimt5TflcONcv5+2kAze7zj+/Y0LDsxXjd2AFyIPEUELEyZxVrZr4KCXHMwE5s FEIdtgRGwruATHKRhUUGmkAZG48gXneaw/JXe8VaXq32AIu2beiRXCH X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Expose the auxiliary clocks through the vDSO. Architectures not using the generic vDSO time framework, namely SPARC64, are not supported. Signed-off-by: Thomas Wei=C3=9Fschuh --- include/vdso/datapage.h | 2 ++ lib/vdso/gettimeofday.c | 49 +++++++++++++++++++++++++++++++++++++++++++++= +++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/include/vdso/datapage.h b/include/vdso/datapage.h index f4c96d9ce674abb07ccd8703f1a04da7631c1677..02533038640e53c40291c7e0913= 9e0f9b32f502a 100644 --- a/include/vdso/datapage.h +++ b/include/vdso/datapage.h @@ -5,6 +5,7 @@ #ifndef __ASSEMBLY__ =20 #include +#include #include #include #include @@ -46,6 +47,7 @@ struct vdso_arch_data { #define VDSO_COARSE (BIT(CLOCK_REALTIME_COARSE) | \ BIT(CLOCK_MONOTONIC_COARSE)) #define VDSO_RAW (BIT(CLOCK_MONOTONIC_RAW)) +#define VDSO_AUX __GENMASK(CLOCK_AUX_LAST, CLOCK_AUX) =20 #define CS_HRES_COARSE 0 #define CS_RAW 1 diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c index c383878bb5445a62d8fea6591e8550183852c2e6..3a54dbb8fe32849cd749e71ec2a= 8be44baf42816 100644 --- a/lib/vdso/gettimeofday.c +++ b/lib/vdso/gettimeofday.c @@ -2,6 +2,7 @@ /* * Generic userspace implementations of gettimeofday() and similar. */ +#include #include #include =20 @@ -74,7 +75,7 @@ static inline bool vdso_cycles_ok(u64 cycles) static __always_inline bool vdso_clockid_valid(clockid_t clock) { /* Check for negative values or invalid clocks */ - return likely((u32) clock < MAX_CLOCKS); + return likely((u32) clock < CLOCK_AUX_LAST); } =20 /* @@ -268,6 +269,48 @@ bool do_coarse(const struct vdso_time_data *vd, const = struct vdso_clock *vc, return true; } =20 +static __always_inline +bool do_aux(const struct vdso_time_data *vd, clockid_t clock, struct __ker= nel_timespec *ts) +{ + const struct vdso_clock *vc; + u64 sec, ns; + u32 seq; + u8 idx; + + if (!IS_ENABLED(CONFIG_POSIX_AUX_CLOCKS)) + return false; + + idx =3D clock - CLOCK_AUX; + vc =3D &vd->aux_clock_data[idx]; + + do { + /* + * Open coded function vdso_read_begin() to handle + * VDSO_CLOCK_TIMENS. See comment in do_hres(). + */ + while ((seq =3D READ_ONCE(vc->seq)) & 1) { + if (IS_ENABLED(CONFIG_TIME_NS) && vc->clock_mode =3D=3D VDSO_CLOCKMODE_= TIMENS) { + vd =3D __arch_get_vdso_u_timens_data(vd); + vc =3D &vd->aux_clock_data[idx]; + break; + } + cpu_relax(); + } + smp_rmb(); + + /* Auxclock disabled? */ + if (vc->clock_mode =3D=3D VDSO_CLOCKMODE_NONE) + return false; + + if (!vdso_get_timestamp(vd, vc, VDSO_BASE_AUX, &sec, &ns)) + return false; + } while (unlikely(vdso_read_retry(vc, seq))); + + vdso_set_timespec(ts, sec, ns); + + return true; +} + static __always_inline bool __cvdso_clock_gettime_common(const struct vdso_time_data *vd, clockid_t cl= ock, struct __kernel_timespec *ts) @@ -289,6 +332,8 @@ __cvdso_clock_gettime_common(const struct vdso_time_dat= a *vd, clockid_t clock, return do_coarse(vd, &vc[CS_HRES_COARSE], clock, ts); else if (msk & VDSO_RAW) vc =3D &vc[CS_RAW]; + else if (msk & VDSO_AUX) + return do_aux(vd, clock, ts); else return false; =20 @@ -433,6 +478,8 @@ bool __cvdso_clock_getres_common(const struct vdso_time= _data *vd, clockid_t cloc * Preserves the behaviour of posix_get_coarse_res(). */ ns =3D LOW_RES_NSEC; + } else if (msk & VDSO_AUX) { + ns =3D aux_clock_resolution_ns(); } else { return false; } --=20 2.50.0 From nobody Wed Oct 8 07:37:00 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1CB926E6F1; Tue, 1 Jul 2025 08:58:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360295; cv=none; b=PMX427KOXUSsQbaQllHtf3+Th8cFW8HF40PfkNGIOYEGU92IJY7LcJTSNl1N8S4KGjFn7mzyD/x37/C32iiVybiK12Aru2avISs4zkKuPVw27c2w+jHpXlUqi7IAlz05wF8E5OT6j5O9wYHVoKnUMemduj7W/M0qUEzu+A+NdoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360295; c=relaxed/simple; bh=bpk3KAQY5N8I4k57sZludGnIuWomX8iO/06DkAxXS9U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=urrf3lBa6HJO7Pc59HBF3UDw4MeWUUQ7OZj+CTgwqRDT7xoMvYRqtJFFwnYF4cbQo1OMrklEInDxRvJ6YLv1YnIDpdJPG6r2VC2Poq3XeJld9ivlmx69/A3h/PukcyStPiHifBaxDebMc5nz/8hxE3mShrASFx60ql1M0rToN7k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=K9BaqrOY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0ld+FVHv; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="K9BaqrOY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0ld+FVHv" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1751360292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1HKU/uJy0IuunrWhxLM2EASE6yRF5K6bEQO5QIgY2ek=; b=K9BaqrOYFqnofn5P2Mt2X6g2ua5GThBRPRyNjGUZC4scdamlJpMYD5gNN573zW/J2bL+31 wrLYKUQpeAfHswC7nPzAEKWEd6XAVCW3kVbu1T6D+uYTW7WgYNtPK4NtQpSkbFVCWJqpMy ygVkULpruELUspdcQEvyIkXrAnToczefld2yN7H0pLbwgtp4nnbtEMOQMc3QZGaurqw3bQ qO0ZyF9ZSvMxNQeF0XVc7Di9v3BFriVSCNqStPIV1b2RsYJWpnldRVtrPYyKk+vinObRtd twC+cM+VJqsIInUsqht9j/u5wZ85mC4SuS5B0eTP5RxHC9bJIYPVTDAbhztbNA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1751360292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1HKU/uJy0IuunrWhxLM2EASE6yRF5K6bEQO5QIgY2ek=; b=0ld+FVHvitgzjdEPmJc5YG8pha2EOVxZLZQXEFjdJHO/97hXtm+rM1dRcF9PN9MjtFmFHP psvwp2Ok0d2zy6DA== Date: Tue, 01 Jul 2025 10:58:07 +0200 Subject: [PATCH 13/14] Revert "selftests: vDSO: parse_vdso: Use UAPI headers instead of libc headers" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250701-vdso-auxclock-v1-13-df7d9f87b9b8@linutronix.de> References: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> In-Reply-To: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> To: Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Shuah Khan , Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Stephen Boyd , Catalin Marinas , Will Deacon , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, Richard Cochran , Christopher Hall , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , Kurt Kanzenbach , Nam Cao , Antoine Tenart , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1751360285; l=1843; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=bpk3KAQY5N8I4k57sZludGnIuWomX8iO/06DkAxXS9U=; b=hKaFZYN5LZWjWFdnd5ob07pCwqSWQ1FiB4gHtjSVxkxW6JM6TYu4NjNH4o5Qpcii7niW8wMfN 4gEk5rzDT8rBZPxvq/KqzJIjggVPd3ZFDJYgqFRkH1+mkuMlafKiRVY X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= This reverts commit c9fbaa879508 ("selftests: vDSO: parse_vdso: Use UAPI he= aders instead of libc headers") The kernel headers were used to make parse_vdso.c compatible with nolibc. Unfortunately linux/elf.h is incompatible with glibc's sys/auxv.h. When using glibc it is therefore not possible build parse_vdso.c as part of= the same compilation unit as its caller as sys/auxv.h is needed for getauxval(). In the meantime nolibc gained its own elf.h, providing compatibility with t= he documented libc interfaces. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/testing/selftests/vDSO/Makefile | 2 -- tools/testing/selftests/vDSO/parse_vdso.c | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/testing/selftests/vDSO/Makefile b/tools/testing/selftest= s/vDSO/Makefile index 12a0614b9fd4983deffe5d6a7cfa06ba8d92a516..67ead1ba6cb9c6d6088680a9c4d= 24a9d19f7231f 100644 --- a/tools/testing/selftests/vDSO/Makefile +++ b/tools/testing/selftests/vDSO/Makefile @@ -20,8 +20,6 @@ endif =20 include ../lib.mk =20 -CFLAGS +=3D $(TOOLS_INCLUDES) - CFLAGS_NOLIBC :=3D -nostdlib -nostdinc -ffreestanding -fno-asynchronous-un= wind-tables \ -fno-stack-protector -include $(top_srcdir)/tools/include/nolibc/nolibc= .h \ -I$(top_srcdir)/tools/include/nolibc/ $(KHDR_INCLUDES) diff --git a/tools/testing/selftests/vDSO/parse_vdso.c b/tools/testing/self= tests/vDSO/parse_vdso.c index 3ff00fb624a44b964cc54954f1f088cabe11a901..c6ff4413ea367ae57bc6a600733= 14b29f938c99d 100644 --- a/tools/testing/selftests/vDSO/parse_vdso.c +++ b/tools/testing/selftests/vDSO/parse_vdso.c @@ -19,8 +19,7 @@ #include #include #include -#include -#include +#include =20 #include "parse_vdso.h" =20 --=20 2.50.0 From nobody Wed Oct 8 07:37:00 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBF432741D1; Tue, 1 Jul 2025 08:58:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360299; cv=none; b=P5gts8mO2T05K1bxjm8YAyuOh3agMJA3YLcV5UCkGSRDdDCUyH0BcVfae7B4qB3pAPO/G3e6nFod/GbWGxZzD9EqZsLY4W2wHEN4hAYXM5QWLalGKIxI3/vPJsFW9kPQoU6gWCV0CT9/U6npqVjxH2TVykhDBJVaVP+sQAL6jsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751360299; c=relaxed/simple; bh=x/PnXWFdRLfiD0A/OSKGxuIkOAxAGhB8JsdPBHMIAYg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cYWZIsO5ue9bSdqc0slhqb6h/Y5Fh3lTn8g/TOKi8SgTE0LwQzxyShyc7/oqfIV5KZS1bxIb4r2JjUrYhnwUtLd+Wz8v9XohFMDqrLSmmUHpnFz5FSepmAwX3RR1gu/4gVqtIg+HjlaEoBruZNzbfvMA8GPI1eFHLghuL3kCnpw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yJy4keyD; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=PlSEIyIg; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yJy4keyD"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="PlSEIyIg" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1751360292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SK3l8BMMu95VGRUTPaxq3odjbGz7PFs+Kx3KugUm1Eo=; b=yJy4keyDvwMT/d9Iuu10ATzWX27er316R8MoS0J/wlG2ms9yMllswmbVSX7F0oNSwves1g 4BHh6Q4jDj04y5tvLIG38Qesc8j4udGrpFb/JzMG0obIbHT6BDsnGHDR3DXhExTQldLZ6p TIasEskPYlMcM5UrKm56HckiWHr+AUvISU8YbBHWzgTK18tmfKhhbgxVDRSJKsCXwJJsdS unOL13ZIK+7PxGSejg9WpLpB+LqhcYWknE+Zk2SB60y6kV+IgHufR9RIF781J+pDe5CBBM +pMyGuApf62S98iO1hYC0KPj1CfUKMGbSZUeLlqo9p2OxoU2n3zbwq/MJ4zTEw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1751360292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SK3l8BMMu95VGRUTPaxq3odjbGz7PFs+Kx3KugUm1Eo=; b=PlSEIyIg2wzGfdV+P8vGns3fGgMZoJ8TdGRsj5fKXuwEfe7qrVEvJ9Z02lp1QogJ04DZst NVCqYmbA/AfuVkAg== Date: Tue, 01 Jul 2025 10:58:08 +0200 Subject: [PATCH 14/14] selftests/timers/auxclock: Test vDSO functionality Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250701-vdso-auxclock-v1-14-df7d9f87b9b8@linutronix.de> References: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> In-Reply-To: <20250701-vdso-auxclock-v1-0-df7d9f87b9b8@linutronix.de> To: Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Shuah Khan , Anna-Maria Behnsen , Frederic Weisbecker , John Stultz , Stephen Boyd , Catalin Marinas , Will Deacon , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, Richard Cochran , Christopher Hall , Frederic Weisbecker , Anna-Maria Behnsen , Miroslav Lichvar , Werner Abt , David Woodhouse , Stephen Boyd , Kurt Kanzenbach , Nam Cao , Antoine Tenart , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1751360285; l=4589; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=x/PnXWFdRLfiD0A/OSKGxuIkOAxAGhB8JsdPBHMIAYg=; b=OA+n1MSc80uZUXpqQjNbqDIekjmoLXtWUGfIg6qkJB8FJfSi1QgdUq+BefaVbWNSC/4NI7as+ cDOwHVLSM6QABo3bS6VhO/hkfNIXLsquyPVrTFpjyRRleSToVAMh0A8 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Extend the auxclock test to also cover the vDSO. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/testing/selftests/timers/auxclock.c | 95 +++++++++++++++++++++++++++= ++-- 1 file changed, 91 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/timers/auxclock.c b/tools/testing/self= tests/timers/auxclock.c index 0ba2f9996114ade3147f0f3aec49904556a23cd4..314037839c1c7dd32ca32722231= c67bc408a2ea3 100644 --- a/tools/testing/selftests/timers/auxclock.c +++ b/tools/testing/selftests/timers/auxclock.c @@ -10,11 +10,16 @@ #include #include #include +#include #include #include =20 #include "../kselftest_harness.h" =20 +#include "../vDSO/parse_vdso.c" +#include "../vDSO/vdso_config.h" +#include "../vDSO/vdso_call.h" + #ifndef CLOCK_AUX #define CLOCK_AUX 16 #endif @@ -133,7 +138,45 @@ static int sys_clock_adjtime64(__kernel_clockid_t cloc= kid, struct __kernel_timex #endif } =20 -FIXTURE(auxclock) {}; +FIXTURE(auxclock) { + int (*vdso_clock_gettime)(__kernel_clockid_t clockid, struct timespec *ts= ); + int (*vdso_clock_gettime64)(__kernel_clockid_t clockid, struct __kernel_t= imespec *ts); + int (*vdso_clock_getres)(__kernel_clockid_t clockid, struct timespec *ts); +}; + +static int vdso_clock_gettime64(FIXTURE_DATA(auxclock) *self, __kernel_clo= ckid_t clockid, + struct __kernel_timespec *ts) +{ + struct timespec _ts; + int ret; + + if (self->vdso_clock_gettime64) { + return VDSO_CALL(self->vdso_clock_gettime64, 2, clockid, ts); + } else if (self->vdso_clock_gettime) { + ret =3D VDSO_CALL(self->vdso_clock_gettime, 2, clockid, &_ts); + if (!ret) + timespec_to_kernel_timespec(&_ts, ts); + return ret; + } else { + return -ENOSYS; + } +} + +static int vdso_clock_getres_time64(FIXTURE_DATA(auxclock) *self, __kernel= _clockid_t clockid, + struct __kernel_timespec *ts) +{ + struct timespec _ts; + int ret; + + if (self->vdso_clock_getres) { + ret =3D VDSO_CALL(self->vdso_clock_getres, 2, clockid, &_ts); + if (!ret) + timespec_to_kernel_timespec(&_ts, ts); + return ret; + } else { + return -ENOSYS; + } +} =20 FIXTURE_VARIANT(auxclock) { __kernel_clockid_t clock; @@ -193,6 +236,18 @@ static void enter_timens(struct __test_metadata *_meta= data) FIXTURE_SETUP(auxclock) { int ret; =20 +#ifdef AT_SYSINFO_EHDR + unsigned long sysinfo_ehdr; + + sysinfo_ehdr =3D getauxval(AT_SYSINFO_EHDR); + if (sysinfo_ehdr) + vdso_init_from_sysinfo_ehdr(sysinfo_ehdr); + + self->vdso_clock_gettime =3D vdso_sym(versions[VDSO_VERSION], names[VDSO_= NAMES][1]); + self->vdso_clock_gettime64 =3D vdso_sym(versions[VDSO_VERSION], names[VDS= O_NAMES][5]); + self->vdso_clock_getres =3D vdso_sym(versions[VDSO_VERSION], names[VDSO_N= AMES][3]); +#endif /* !AT_SYSINFO_EHDR */ + ret =3D configure_auxclock(variant->clock, variant->clock_enabled); if (ret =3D=3D -ENOENT) SKIP(return, "auxclocks not enabled"); @@ -220,6 +275,20 @@ TEST_F(auxclock, sys_clock_getres) { ASSERT_EQ(1, ts.tv_nsec); } =20 +TEST_F(auxclock, vdso_clock_getres) { + struct __kernel_timespec ts; + int ret; + + ret =3D vdso_clock_getres_time64(self, variant->clock, &ts); + if (ret =3D=3D -ENOSYS) { + SKIP(return, "no clock_getres() in vDSO"); + } else { + ASSERT_EQ(0, ret); + ASSERT_EQ(0, ts.tv_sec); + ASSERT_EQ(1, ts.tv_nsec); + } +} + TEST_F(auxclock, sys_clock_gettime) { struct __kernel_timespec ts; int ret; @@ -233,6 +302,20 @@ TEST_F(auxclock, sys_clock_gettime) { } } =20 +TEST_F(auxclock, vdso_clock_gettime) { + struct __kernel_timespec ts; + int ret; + + ret =3D vdso_clock_gettime64(self, variant->clock, &ts); + if (ret =3D=3D -ENOSYS) { + SKIP(return, "no clock_gettime() in vDSO"); + } else if (variant->clock_enabled) { + ASSERT_EQ(0, ret); + } else { + ASSERT_EQ(-ENODEV, ret); + } +} + static void auxclock_validate_progression(struct __test_metadata *_metadat= a, const struct __kernel_timespec *a, const struct __kernel_timespec *b) @@ -310,9 +393,13 @@ TEST_F(auxclock, progression) { auxclock_validate_progression(_metadata, &a, &b); =20 memset(&a, 0, sizeof(a)); - ret =3D sys_clock_gettime64(variant->clock, &a); - ASSERT_EQ(0, ret); - auxclock_validate_progression(_metadata, &b, &a); + ret =3D vdso_clock_gettime64(self, variant->clock, &a); + if (ret =3D=3D -ENOSYS) { + a =3D b; + } else { + ASSERT_EQ(0, ret); + auxclock_validate_progression(_metadata, &b, &a); + } } } =20 --=20 2.50.0