From nobody Thu Apr 2 22:17:53 2026 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 2470D3ECBC7 for ; Thu, 26 Mar 2026 11:42:51 +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=1774525383; cv=none; b=msTS+YPkiqITPrE4nzTUbaLCpPoiI8NpY8iTMKGgeeLvHu5P2ViliKXv4bcdtqHvgf/PrCz6yxja0I5aa+dcNhJQhNjXx7HUXNlkjyY0ZkFEyLgaWf9BuS06fi/5OpDGbmQ4OH2yUKikgTXJ/IN8mlcLfLSJBGa6CLPD6DnduOg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774525383; c=relaxed/simple; bh=0ekHj4NGVxK5k9UYAdGJhiL1xHeVfuoqJkULMYes1D4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CFx4HmrOvJemAris3BIGPn8VJu5j1t/ugUyToHgJolAdaoo6azIGiRHjeKwmZ9FE5O6W++4T/UQaATuhynKgGa7VUP9OW0Esfr0pfDDLKzApXKKcDttuVVTW1PoCFUpcCm86nz5Jb/0MTC3jAsKri82KYtlct60lTyeqc5zMBp4= 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=piQ0gsbq; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=27haOcwA; 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="piQ0gsbq"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="27haOcwA" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1774525369; 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=Lhnaw1thTyqURunZMLZ0Bbjp0/GmCs9wDDm6BgZsAOk=; b=piQ0gsbqVgwUF0wytpg7pSYqkpOW+dpzi8EgrCmKkfR3ElcLqDeCKvy9UVcxCFyMmDxMvl HMtMM6GHJxvs1hFGVBsU1enf1+gv2TghBoziJTgOJdr3gQXsRvcgs2tv8MwIgL1l1/ZPez sE/TpMTpsSCt1Y6AWnCddy0dyQQ8Nz47vsaGsp78dOMHkWIaxRxMJ6QEDbEZz0QG0WH3N6 hcZLwigadX7oWRXu5tLZ4IJ4S7Mwy4qW1MO0eq/Hk8iZj9JjNR5BG8o/veCV2NgRGa1e0y WTg2uiTOz3pt3d+PDU+8urcanYmeZ/LGsHBUhpTTkMNY/5tHgUWQr4t+TTDJ+g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1774525369; 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=Lhnaw1thTyqURunZMLZ0Bbjp0/GmCs9wDDm6BgZsAOk=; b=27haOcwAyd0pidRQ0T39ZpkIXkLEMEnawlqi81OYnDWny8mWeoXtUn+4D5TUp1SamKyK9e Ur9dOUYEv2thN8Bw== Date: Thu, 26 Mar 2026 12:42:30 +0100 Subject: [PATCH v2 1/2] vdso/timens: Move functions to new file 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: <20260326-vdso-timens-decoupling-v2-1-c82693a7775f@linutronix.de> References: <20260326-vdso-timens-decoupling-v2-0-c82693a7775f@linutronix.de> In-Reply-To: <20260326-vdso-timens-decoupling-v2-0-c82693a7775f@linutronix.de> To: Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Andy Lutomirski , Vincenzo Frascino Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1774525367; l=13875; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=0ekHj4NGVxK5k9UYAdGJhiL1xHeVfuoqJkULMYes1D4=; b=7/bCvWbfOgXnTPxwcDzEfe7YitsbjIMKN05gBi3zd3XsXM1Z4NgU+SQfzJNutgPMeSVG5xWgV yk2xUJ99YzYC0+LStYWHHff2/+fHMP7UqzOCJ4s/uaziZyd5KoDgLzR X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= As a preparation of the untangling of time namespaces and the vDSO, move the glue functions between those subsystems into a new file. While at it, switch the mutex lock in timens_set_vvar_page() to guard(). Signed-off-by: Thomas Wei=C3=9Fschuh --- MAINTAINERS | 2 + include/linux/time_namespace.h | 8 --- kernel/time/Makefile | 2 +- kernel/time/namespace.c | 124 ++------------------------------ kernel/time/namespace_internal.h | 13 ++++ kernel/time/namespace_vdso.c | 148 +++++++++++++++++++++++++++++++++++= ++++ lib/vdso/datastore.c | 25 ------- 7 files changed, 168 insertions(+), 154 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 77fdfcb55f06..6ad74a5196d1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10768,6 +10768,7 @@ S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers/vd= so F: include/asm-generic/vdso/vsyscall.h F: include/vdso/ +F: kernel/time/namespace_vdso.c F: kernel/time/vsyscall.c F: lib/vdso/ F: tools/testing/selftests/vDSO/ @@ -21000,6 +21001,7 @@ F: include/trace/events/timer* F: kernel/time/itimer.c F: kernel/time/posix-* F: kernel/time/namespace.c +F: kernel/time/namespace_vdso.c =20 POWER MANAGEMENT CORE M: "Rafael J. Wysocki" diff --git a/include/linux/time_namespace.h b/include/linux/time_namespace.h index c514d0e5a45c..0421bf1b13d7 100644 --- a/include/linux/time_namespace.h +++ b/include/linux/time_namespace.h @@ -38,8 +38,6 @@ static inline struct time_namespace *to_time_ns(struct ns= _common *ns) return container_of(ns, struct time_namespace, ns); } void __init time_ns_init(void); -extern int vdso_join_timens(struct task_struct *task, - struct time_namespace *ns); extern void timens_commit(struct task_struct *tsk, struct time_namespace *= ns); =20 static inline struct time_namespace *get_time_ns(struct time_namespace *ns) @@ -117,12 +115,6 @@ static inline void __init time_ns_init(void) { } =20 -static inline int vdso_join_timens(struct task_struct *task, - struct time_namespace *ns) -{ - return 0; -} - static inline void timens_commit(struct task_struct *tsk, struct time_namespace *ns) { diff --git a/kernel/time/Makefile b/kernel/time/Makefile index f7d52d9543cc..662bccb3b7f9 100644 --- a/kernel/time/Makefile +++ b/kernel/time/Makefile @@ -29,6 +29,6 @@ endif obj-$(CONFIG_GENERIC_GETTIMEOFDAY) +=3D vsyscall.o obj-$(CONFIG_DEBUG_FS) +=3D timekeeping_debug.o obj-$(CONFIG_TEST_UDELAY) +=3D test_udelay.o -obj-$(CONFIG_TIME_NS) +=3D namespace.o +obj-$(CONFIG_TIME_NS) +=3D namespace.o namespace_vdso.o obj-$(CONFIG_TEST_CLOCKSOURCE_WATCHDOG) +=3D clocksource-wdtest.o obj-$(CONFIG_TIME_KUNIT_TEST) +=3D time_test.o diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c index 652744e00eb4..903f55a2dfb2 100644 --- a/kernel/time/namespace.c +++ b/kernel/time/namespace.c @@ -19,7 +19,7 @@ #include #include =20 -#include +#include "namespace_internal.h" =20 ktime_t do_timens_ktime_to_host(clockid_t clockid, ktime_t tim, struct timens_offsets *ns_offsets) @@ -138,117 +138,7 @@ struct time_namespace *copy_time_ns(u64 flags, return clone_time_ns(user_ns, old_ns); } =20 -static struct timens_offset offset_from_ts(struct timespec64 off) -{ - struct timens_offset ret; - - ret.sec =3D off.tv_sec; - ret.nsec =3D off.tv_nsec; - - return ret; -} - -/* - * A time namespace VVAR page has the same layout as the VVAR page which - * contains the system wide VDSO data. - * - * For a normal task the VVAR pages are installed in the normal ordering: - * VVAR - * PVCLOCK - * HVCLOCK - * TIMENS <- Not really required - * - * Now for a timens task the pages are installed in the following order: - * TIMENS - * PVCLOCK - * HVCLOCK - * VVAR - * - * The check for vdso_clock->clock_mode is in the unlikely path of - * the seq begin magic. So for the non-timens case most of the time - * 'seq' is even, so the branch is not taken. - * - * If 'seq' is odd, i.e. a concurrent update is in progress, the extra che= ck - * for vdso_clock->clock_mode is a non-issue. The task is spin waiting for= the - * update to finish and for 'seq' to become even anyway. - * - * Timens page has vdso_clock->clock_mode set to VDSO_CLOCKMODE_TIMENS whi= ch - * enforces the time namespace handling path. - */ -static void timens_setup_vdso_clock_data(struct vdso_clock *vc, - struct time_namespace *ns) -{ - struct timens_offset *offset =3D vc->offset; - struct timens_offset monotonic =3D offset_from_ts(ns->offsets.monotonic); - struct timens_offset boottime =3D offset_from_ts(ns->offsets.boottime); - - vc->seq =3D 1; - vc->clock_mode =3D VDSO_CLOCKMODE_TIMENS; - offset[CLOCK_MONOTONIC] =3D monotonic; - offset[CLOCK_MONOTONIC_RAW] =3D monotonic; - offset[CLOCK_MONOTONIC_COARSE] =3D monotonic; - offset[CLOCK_BOOTTIME] =3D boottime; - offset[CLOCK_BOOTTIME_ALARM] =3D boottime; -} - -struct page *find_timens_vvar_page(struct vm_area_struct *vma) -{ - if (likely(vma->vm_mm =3D=3D current->mm)) - return current->nsproxy->time_ns->vvar_page; - - /* - * VM_PFNMAP | VM_IO protect .fault() handler from being called - * through interfaces like /proc/$pid/mem or - * process_vm_{readv,writev}() as long as there's no .access() - * in special_mapping_vmops(). - * For more details check_vma_flags() and __access_remote_vm() - */ - - WARN(1, "vvar_page accessed remotely"); - - return NULL; -} - -/* - * Protects possibly multiple offsets writers racing each other - * and tasks entering the namespace. - */ -static DEFINE_MUTEX(offset_lock); - -static void timens_set_vvar_page(struct task_struct *task, - struct time_namespace *ns) -{ - struct vdso_time_data *vdata; - struct vdso_clock *vc; - unsigned int i; - - if (ns =3D=3D &init_time_ns) - return; - - /* Fast-path, taken by every task in namespace except the first. */ - if (likely(ns->frozen_offsets)) - return; - - mutex_lock(&offset_lock); - /* Nothing to-do: vvar_page has been already initialized. */ - if (ns->frozen_offsets) - goto out; - - ns->frozen_offsets =3D true; - vdata =3D page_address(ns->vvar_page); - vc =3D vdata->clock_data; - - for (i =3D 0; i < CS_BASES; i++) - timens_setup_vdso_clock_data(&vc[i], ns); - - 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); -} +DEFINE_MUTEX(timens_offset_lock); =20 void free_time_ns(struct time_namespace *ns) { @@ -298,12 +188,6 @@ static void timens_put(struct ns_common *ns) put_time_ns(to_time_ns(ns)); } =20 -void timens_commit(struct task_struct *tsk, struct time_namespace *ns) -{ - timens_set_vvar_page(tsk, ns); - vdso_join_timens(tsk, ns); -} - static int timens_install(struct nsset *nsset, struct ns_common *new) { struct nsproxy *nsproxy =3D nsset->nsproxy; @@ -428,7 +312,7 @@ int proc_timens_set_offset(struct file *file, struct ta= sk_struct *p, goto out; } =20 - mutex_lock(&offset_lock); + mutex_lock(&timens_offset_lock); if (time_ns->frozen_offsets) { err =3D -EACCES; goto out_unlock; @@ -453,7 +337,7 @@ int proc_timens_set_offset(struct file *file, struct ta= sk_struct *p, } =20 out_unlock: - mutex_unlock(&offset_lock); + mutex_unlock(&timens_offset_lock); out: put_time_ns(time_ns); =20 diff --git a/kernel/time/namespace_internal.h b/kernel/time/namespace_inter= nal.h new file mode 100644 index 000000000000..e85da11abb4d --- /dev/null +++ b/kernel/time/namespace_internal.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TIME_NAMESPACE_INTERNAL_H +#define _TIME_NAMESPACE_INTERNAL_H + +#include + +/* + * Protects possibly multiple offsets writers racing each other + * and tasks entering the namespace. + */ +extern struct mutex timens_offset_lock; + +#endif /* _TIME_NAMESPACE_INTERNAL_H */ diff --git a/kernel/time/namespace_vdso.c b/kernel/time/namespace_vdso.c new file mode 100644 index 000000000000..c3582befa7a4 --- /dev/null +++ b/kernel/time/namespace_vdso.c @@ -0,0 +1,148 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Author: Andrei Vagin + * Author: Dmitry Safonov + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "namespace_internal.h" + +static struct timens_offset offset_from_ts(struct timespec64 off) +{ + struct timens_offset ret; + + ret.sec =3D off.tv_sec; + ret.nsec =3D off.tv_nsec; + + return ret; +} + +/* + * A time namespace VVAR page has the same layout as the VVAR page which + * contains the system wide VDSO data. + * + * For a normal task the VVAR pages are installed in the normal ordering: + * VVAR + * PVCLOCK + * HVCLOCK + * TIMENS <- Not really required + * + * Now for a timens task the pages are installed in the following order: + * TIMENS + * PVCLOCK + * HVCLOCK + * VVAR + * + * The check for vdso_clock->clock_mode is in the unlikely path of + * the seq begin magic. So for the non-timens case most of the time + * 'seq' is even, so the branch is not taken. + * + * If 'seq' is odd, i.e. a concurrent update is in progress, the extra che= ck + * for vdso_clock->clock_mode is a non-issue. The task is spin waiting for= the + * update to finish and for 'seq' to become even anyway. + * + * Timens page has vdso_clock->clock_mode set to VDSO_CLOCKMODE_TIMENS whi= ch + * enforces the time namespace handling path. + */ +static void timens_setup_vdso_clock_data(struct vdso_clock *vc, + struct time_namespace *ns) +{ + struct timens_offset *offset =3D vc->offset; + struct timens_offset monotonic =3D offset_from_ts(ns->offsets.monotonic); + struct timens_offset boottime =3D offset_from_ts(ns->offsets.boottime); + + vc->seq =3D 1; + vc->clock_mode =3D VDSO_CLOCKMODE_TIMENS; + offset[CLOCK_MONOTONIC] =3D monotonic; + offset[CLOCK_MONOTONIC_RAW] =3D monotonic; + offset[CLOCK_MONOTONIC_COARSE] =3D monotonic; + offset[CLOCK_BOOTTIME] =3D boottime; + offset[CLOCK_BOOTTIME_ALARM] =3D boottime; +} + +struct page *find_timens_vvar_page(struct vm_area_struct *vma) +{ + if (likely(vma->vm_mm =3D=3D current->mm)) + return current->nsproxy->time_ns->vvar_page; + + /* + * VM_PFNMAP | VM_IO protect .fault() handler from being called + * through interfaces like /proc/$pid/mem or + * process_vm_{readv,writev}() as long as there's no .access() + * in special_mapping_vmops(). + * For more details check_vma_flags() and __access_remote_vm() + */ + + WARN(1, "vvar_page accessed remotely"); + + return NULL; +} + +static void timens_set_vvar_page(struct task_struct *task, + struct time_namespace *ns) +{ + struct vdso_time_data *vdata; + struct vdso_clock *vc; + unsigned int i; + + if (ns =3D=3D &init_time_ns) + return; + + /* Fast-path, taken by every task in namespace except the first. */ + if (likely(ns->frozen_offsets)) + return; + + guard(mutex)(&timens_offset_lock); + /* Nothing to-do: vvar_page has been already initialized. */ + if (ns->frozen_offsets) + return; + + ns->frozen_offsets =3D true; + vdata =3D page_address(ns->vvar_page); + vc =3D vdata->clock_data; + + for (i =3D 0; i < CS_BASES; i++) + timens_setup_vdso_clock_data(&vc[i], ns); + + 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); + } +} + +/* + * The vvar page layout depends on whether a task belongs to the root or + * non-root time namespace. Whenever a task changes its namespace, the VVAR + * page tables are cleared and then they will be re-faulted with a + * corresponding layout. + * See also the comment near timens_setup_vdso_clock_data() for details. + */ +static int vdso_join_timens(struct task_struct *task, struct time_namespac= e *ns) +{ + struct mm_struct *mm =3D task->mm; + struct vm_area_struct *vma; + VMA_ITERATOR(vmi, mm, 0); + + mmap_read_lock(mm); + for_each_vma(vmi, vma) { + if (vma_is_special_mapping(vma, &vdso_vvar_mapping)) + zap_vma_pages(vma); + } + mmap_read_unlock(mm); + + return 0; +} + +void timens_commit(struct task_struct *tsk, struct time_namespace *ns) +{ + timens_set_vvar_page(tsk, ns); + vdso_join_timens(tsk, ns); +} diff --git a/lib/vdso/datastore.c b/lib/vdso/datastore.c index faebf5b7cd6e..cf5d784a4a5a 100644 --- a/lib/vdso/datastore.c +++ b/lib/vdso/datastore.c @@ -132,28 +132,3 @@ struct vm_area_struct *vdso_install_vvar_mapping(struc= t mm_struct *mm, unsigned VM_MIXEDMAP | VM_SEALED_SYSMAP, &vdso_vvar_mapping); } - -#ifdef CONFIG_TIME_NS -/* - * The vvar page layout depends on whether a task belongs to the root or - * non-root time namespace. Whenever a task changes its namespace, the VVAR - * page tables are cleared and then they will be re-faulted with a - * corresponding layout. - * See also the comment near timens_setup_vdso_clock_data() for details. - */ -int vdso_join_timens(struct task_struct *task, struct time_namespace *ns) -{ - struct mm_struct *mm =3D task->mm; - struct vm_area_struct *vma; - VMA_ITERATOR(vmi, mm, 0); - - mmap_read_lock(mm); - for_each_vma(vmi, vma) { - if (vma_is_special_mapping(vma, &vdso_vvar_mapping)) - zap_vma_pages(vma); - } - mmap_read_unlock(mm); - - return 0; -} -#endif --=20 2.53.0 From nobody Thu Apr 2 22:17:53 2026 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 561B92F6192 for ; Thu, 26 Mar 2026 11:42:52 +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=1774525380; cv=none; b=GPHPWZ1iUo884LOtWlBFjZRz6Nop0DUkDZrq8JGR5tFfdnIsqZ0muCsnz1QJUPpYthIvbq4WTnIWhP4ZQv7wUrtdMNJGlmtxrZ1mn9MDwnaXmGD6CphHT1l7d0S8K1KMIPUTWOSYgiZra9p7u7d5tB9sxj8tqnhc0NHmj0cGq58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774525380; c=relaxed/simple; bh=s9L9qWJGOlJsU7ojUyTnh2exZhu8oFoOvBAXvYIA56o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fdYLM/ROcmb7d81OkzW1r/IzBGApUri13acYofxMIiGDMZC5n4kDG3bRIRNQLWB4/pIKT3iLm+LZ9oeQpz9aD57hFlAhmfmIGzbACN0CyBdBZTPaGLorFebGB7XzCg46hhs5QtTgEWU6oa+CyI7E+OUNSS3Dn+dtm1CcLnnI0T4= 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=YnX9tOoi; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cvSEiYDX; 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="YnX9tOoi"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cvSEiYDX" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1774525370; 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=Fzmp4Ecp8vqK8i5tsguuWLrV1tEl3U2b/hyDkVrtqYQ=; b=YnX9tOoi/q5n2Kq3BOPG3WZPQN83Oe8/13vCII47SydK+ueZgKWK8SeLMZU43ZtMkdQ0gP 9w21xktdsrSFsirwvOcnr5jx5oYzNDwibQR2jTdvXuo4TVYipKMqPnWi5OsnZVsFuqZdbR lUDLHPYjq5xwgrBiQurVXXvcjgZSA64m+dorb7yWyqUc5VYC6rkvIsmGe5zutKWLLIOtEB njW9rVl3poI+x4X7nCrW8aLG9m18OQK9KgBFHZQLyUsGq9btB86PSEJ4rM/Xn2X1UTHWHD Hb4Iz0VKWnNnO+duPro2+ZXsY/YS24q/ZUs+GkSzJSoU7TjlJc/KW284N3hcwQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1774525370; 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=Fzmp4Ecp8vqK8i5tsguuWLrV1tEl3U2b/hyDkVrtqYQ=; b=cvSEiYDXmEn1iMsx/fOk1TzTAJrA8ugnWmz+PZA83KArhst46azV3HB97nur+BQ6cWWF1f LqUJQOH1Zyv42hBA== Date: Thu, 26 Mar 2026 12:42:31 +0100 Subject: [PATCH v2 2/2] timens: Remove dependency on the vDSO 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: <20260326-vdso-timens-decoupling-v2-2-c82693a7775f@linutronix.de> References: <20260326-vdso-timens-decoupling-v2-0-c82693a7775f@linutronix.de> In-Reply-To: <20260326-vdso-timens-decoupling-v2-0-c82693a7775f@linutronix.de> To: Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Andy Lutomirski , Vincenzo Frascino Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1774525367; l=7106; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=s9L9qWJGOlJsU7ojUyTnh2exZhu8oFoOvBAXvYIA56o=; b=s4+Kbd4P9jLJDlJ58itENt2QVfvdcDHKBH7xUr8QTEzTX24jEAkNzVN9TLtVveguz8+upEvq3 qEnQZUxceqUC4riJ/H/pjhk9p190Q9dh7UGUk2ilxFn7kzhwRmf0nQG X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Previously, missing time namespace support in the vDSO meant that time namespaces needed to be disabled globally. This was expressed in a hard dependency on the generic vDSO library. This also meant that architectures without any vDSO or only a stub vDSO could not enable time namespaces. Now that all architectures using a real vDSO are using the generic library, that dependency is not necessary anymore. Remove the dependency and let all architectures enable time namespaces. Signed-off-by: Thomas Wei=C3=9Fschuh --- include/linux/time_namespace.h | 28 ++++++++++++++++------------ init/Kconfig | 4 +++- kernel/time/Makefile | 3 ++- kernel/time/namespace.c | 8 ++++---- kernel/time/namespace_internal.h | 15 +++++++++++++++ kernel/time/namespace_vdso.c | 14 ++++++++++++++ 6 files changed, 54 insertions(+), 18 deletions(-) diff --git a/include/linux/time_namespace.h b/include/linux/time_namespace.h index 0421bf1b13d7..c1de21a27c34 100644 --- a/include/linux/time_namespace.h +++ b/include/linux/time_namespace.h @@ -25,7 +25,9 @@ struct time_namespace { struct ucounts *ucounts; struct ns_common ns; struct timens_offsets offsets; +#ifdef CONFIG_TIME_NS_VDSO struct page *vvar_page; +#endif /* If set prevents changing offsets after any task joined namespace. */ bool frozen_offsets; } __randomize_layout; @@ -38,7 +40,6 @@ static inline struct time_namespace *to_time_ns(struct ns= _common *ns) return container_of(ns, struct time_namespace, ns); } void __init time_ns_init(void); -extern void timens_commit(struct task_struct *tsk, struct time_namespace *= ns); =20 static inline struct time_namespace *get_time_ns(struct time_namespace *ns) { @@ -51,7 +52,6 @@ struct time_namespace *copy_time_ns(u64 flags, struct time_namespace *old_ns); void free_time_ns(struct time_namespace *ns); void timens_on_fork(struct nsproxy *nsproxy, struct task_struct *tsk); -struct page *find_timens_vvar_page(struct vm_area_struct *vma); =20 static inline void put_time_ns(struct time_namespace *ns) { @@ -115,11 +115,6 @@ static inline void __init time_ns_init(void) { } =20 -static inline void timens_commit(struct task_struct *tsk, - struct time_namespace *ns) -{ -} - static inline struct time_namespace *get_time_ns(struct time_namespace *ns) { return NULL; @@ -146,11 +141,6 @@ static inline void timens_on_fork(struct nsproxy *nspr= oxy, return; } =20 -static inline struct page *find_timens_vvar_page(struct vm_area_struct *vm= a) -{ - return NULL; -} - static inline void timens_add_monotonic(struct timespec64 *ts) { } static inline void timens_add_boottime(struct timespec64 *ts) { } =20 @@ -167,4 +157,18 @@ static inline ktime_t timens_ktime_to_host(clockid_t c= lockid, ktime_t tim) } #endif =20 +#ifdef CONFIG_TIME_NS_VDSO +extern void timens_commit(struct task_struct *tsk, struct time_namespace *= ns); +struct page *find_timens_vvar_page(struct vm_area_struct *vma); +#else /* !CONFIG_TIME_NS_VDSO */ +static inline void timens_commit(struct task_struct *tsk, struct time_name= space *ns) +{ +} + +static inline struct page *find_timens_vvar_page(struct vm_area_struct *vm= a) +{ + return NULL; +} +#endif /* CONFIG_TIME_NS_VDSO */ + #endif /* _LINUX_TIMENS_H */ diff --git a/init/Kconfig b/init/Kconfig index 444ce811ea67..5e710b03a27a 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1386,12 +1386,14 @@ config UTS_NS =20 config TIME_NS bool "TIME namespace" - depends on GENERIC_GETTIMEOFDAY default y help In this namespace boottime and monotonic clocks can be set. The time will keep going with the same pace. =20 +config TIME_NS_VDSO + def_bool TIME_NS && GENERIC_GETTIMEOFDAY + config IPC_NS bool "IPC namespace" depends on (SYSVIPC || POSIX_MQUEUE) diff --git a/kernel/time/Makefile b/kernel/time/Makefile index 662bccb3b7f9..eaf290c972f9 100644 --- a/kernel/time/Makefile +++ b/kernel/time/Makefile @@ -29,6 +29,7 @@ endif obj-$(CONFIG_GENERIC_GETTIMEOFDAY) +=3D vsyscall.o obj-$(CONFIG_DEBUG_FS) +=3D timekeeping_debug.o obj-$(CONFIG_TEST_UDELAY) +=3D test_udelay.o -obj-$(CONFIG_TIME_NS) +=3D namespace.o namespace_vdso.o +obj-$(CONFIG_TIME_NS) +=3D namespace.o +obj-$(CONFIG_TIME_NS_VDSO) +=3D namespace_vdso.o obj-$(CONFIG_TEST_CLOCKSOURCE_WATCHDOG) +=3D clocksource-wdtest.o obj-$(CONFIG_TIME_KUNIT_TEST) +=3D time_test.o diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c index 903f55a2dfb2..42302cc3f3fb 100644 --- a/kernel/time/namespace.c +++ b/kernel/time/namespace.c @@ -93,8 +93,8 @@ static struct time_namespace *clone_time_ns(struct user_n= amespace *user_ns, if (!ns) goto fail_dec; =20 - ns->vvar_page =3D alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO); - if (!ns->vvar_page) + err =3D timens_vdso_alloc_vvar_page(ns); + if (err) goto fail_free; =20 err =3D ns_common_init(ns); @@ -109,7 +109,7 @@ static struct time_namespace *clone_time_ns(struct user= _namespace *user_ns, return ns; =20 fail_free_page: - __free_page(ns->vvar_page); + timens_vdso_free_vvar_page(ns); fail_free: kfree(ns); fail_dec: @@ -146,7 +146,7 @@ void free_time_ns(struct time_namespace *ns) dec_time_namespaces(ns->ucounts); put_user_ns(ns->user_ns); ns_common_free(ns); - __free_page(ns->vvar_page); + timens_vdso_free_vvar_page(ns); /* Concurrent nstree traversal depends on a grace period. */ kfree_rcu(ns, ns.ns_rcu); } diff --git a/kernel/time/namespace_internal.h b/kernel/time/namespace_inter= nal.h index e85da11abb4d..b37ba179f43b 100644 --- a/kernel/time/namespace_internal.h +++ b/kernel/time/namespace_internal.h @@ -4,10 +4,25 @@ =20 #include =20 +struct time_namespace; + /* * Protects possibly multiple offsets writers racing each other * and tasks entering the namespace. */ extern struct mutex timens_offset_lock; =20 +#ifdef CONFIG_TIME_NS_VDSO +int timens_vdso_alloc_vvar_page(struct time_namespace *ns); +void timens_vdso_free_vvar_page(struct time_namespace *ns); +#else /* !CONFIG_TIME_NS_VDSO */ +static inline int timens_vdso_alloc_vvar_page(struct time_namespace *ns) +{ + return 0; +} +static inline void timens_vdso_free_vvar_page(struct time_namespace *ns) +{ +} +#endif /* CONFIG_TIME_NS_VDSO */ + #endif /* _TIME_NAMESPACE_INTERNAL_H */ diff --git a/kernel/time/namespace_vdso.c b/kernel/time/namespace_vdso.c index c3582befa7a4..ea37047801e7 100644 --- a/kernel/time/namespace_vdso.c +++ b/kernel/time/namespace_vdso.c @@ -146,3 +146,17 @@ void timens_commit(struct task_struct *tsk, struct tim= e_namespace *ns) timens_set_vvar_page(tsk, ns); vdso_join_timens(tsk, ns); } + +int timens_vdso_alloc_vvar_page(struct time_namespace *ns) +{ + ns->vvar_page =3D alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO); + if (!ns->vvar_page) + return -ENOMEM; + + return 0; +} + +void timens_vdso_free_vvar_page(struct time_namespace *ns) +{ + __free_page(ns->vvar_page); +} --=20 2.53.0