]> www.infradead.org Git - users/willy/xarray.git/commitdiff
arm64/vdso: Add time namespace page
authorAndrei Vagin <avagin@gmail.com>
Wed, 24 Jun 2020 08:33:18 +0000 (01:33 -0700)
committerCatalin Marinas <catalin.marinas@arm.com>
Fri, 24 Jul 2020 12:15:20 +0000 (13:15 +0100)
Allocate the time namespace page among VVAR pages.  Provide
__arch_get_timens_vdso_data() helper for VDSO code to get the
code-relative position of VVARs on that special page.

If a task belongs to a time namespace then the VVAR page which contains
the system wide VDSO data is replaced with a namespace specific page
which has the same layout as the VVAR page. That page has vdso_data->seq
set to 1 to enforce the slow path and vdso_data->clock_mode set to
VCLOCK_TIMENS to enforce the time namespace handling path.

The extra check in the case that vdso_data->seq is odd, e.g. a concurrent
update of the VDSO data is in progress, is not really affecting regular
tasks which are not part of a time namespace as the task is spin waiting
for the update to finish and vdso_data->seq to become even again.

If a time namespace task hits that code path, it invokes the corresponding
time getter function which retrieves the real VVAR page, reads host time
and then adds the offset for the requested clock which is stored in the
special VVAR page.

The time-namespace page isn't allocated on !CONFIG_TIME_NAMESPACE, but
vma is the same size, which simplifies criu/vdso migration between
different kernel configs.

Signed-off-by: Andrei Vagin <avagin@gmail.com>
Reviewed-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Reviewed-by: Dmitry Safonov <dima@arista.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/20200624083321.144975-4-avagin@gmail.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/include/asm/vdso.h
arch/arm64/include/asm/vdso/compat_gettimeofday.h
arch/arm64/include/asm/vdso/gettimeofday.h
arch/arm64/kernel/vdso.c
arch/arm64/kernel/vdso/vdso.lds.S
arch/arm64/kernel/vdso32/vdso.lds.S
include/vdso/datapage.h

index 07468428fd2907a6e9453e840da0d95694fcf541..f99dcb94b438d21482bf7938542abf24f9dfdaa3 100644 (file)
@@ -12,6 +12,8 @@
  */
 #define VDSO_LBASE     0x0
 
+#define __VVAR_PAGES    2
+
 #ifndef __ASSEMBLY__
 
 #include <generated/vdso-offsets.h>
index b6907ae78e5303bc45804faeb83d3d002d7d28ad..b7c549d46d1845905a295bf35b48e1262d990e4d 100644 (file)
@@ -152,6 +152,18 @@ static __always_inline const struct vdso_data *__arch_get_vdso_data(void)
        return ret;
 }
 
+#ifdef CONFIG_TIME_NS
+static __always_inline const struct vdso_data *__arch_get_timens_vdso_data(void)
+{
+       const struct vdso_data *ret;
+
+       /* See __arch_get_vdso_data(). */
+       asm volatile("mov %0, %1" : "=r"(ret) : "r"(_timens_data));
+
+       return ret;
+}
+#endif
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* __ASM_VDSO_GETTIMEOFDAY_H */
index afba6ba332f8bdb8a2a7c40ce196c2306a2db715..cf39eae5eaafad1ee4957a75a392d179eddea5d2 100644 (file)
@@ -96,6 +96,14 @@ const struct vdso_data *__arch_get_vdso_data(void)
        return _vdso_data;
 }
 
+#ifdef CONFIG_TIME_NS
+static __always_inline
+const struct vdso_data *__arch_get_timens_vdso_data(void)
+{
+       return _timens_data;
+}
+#endif
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* __ASM_VDSO_GETTIMEOFDAY_H */
index 33ac18060bfc2e881b41fde932b13e6d1be28391..fcb5597269204657cc43b7378e40548f5b19515a 100644 (file)
@@ -40,6 +40,12 @@ enum vdso_abi {
 #endif /* CONFIG_COMPAT_VDSO */
 };
 
+enum vvar_pages {
+       VVAR_DATA_PAGE_OFFSET,
+       VVAR_TIMENS_PAGE_OFFSET,
+       VVAR_NR_PAGES,
+};
+
 struct vdso_abi_info {
        const char *name;
        const char *vdso_code_start;
@@ -125,6 +131,11 @@ static int __vdso_init(enum vdso_abi abi)
 }
 
 #ifdef CONFIG_TIME_NS
+struct vdso_data *arch_get_vdso_data(void *vvar_page)
+{
+       return (struct vdso_data *)(vvar_page);
+}
+
 /*
  * The vvar mapping contains data for a specific time namespace, so when a task
  * changes namespace we must unmap its vvar data for the old namespace.
@@ -173,9 +184,11 @@ static int __setup_additional_pages(enum vdso_abi abi,
        unsigned long gp_flags = 0;
        void *ret;
 
+       BUILD_BUG_ON(VVAR_NR_PAGES != __VVAR_PAGES);
+
        vdso_text_len = vdso_info[abi].vdso_pages << PAGE_SHIFT;
        /* Be sure to map the data page */
-       vdso_mapping_len = vdso_text_len + PAGE_SIZE;
+       vdso_mapping_len = vdso_text_len + VVAR_NR_PAGES * PAGE_SIZE;
 
        vdso_base = get_unmapped_area(NULL, 0, vdso_mapping_len, 0, 0);
        if (IS_ERR_VALUE(vdso_base)) {
@@ -183,7 +196,7 @@ static int __setup_additional_pages(enum vdso_abi abi,
                goto up_fail;
        }
 
-       ret = _install_special_mapping(mm, vdso_base, PAGE_SIZE,
+       ret = _install_special_mapping(mm, vdso_base, VVAR_NR_PAGES * PAGE_SIZE,
                                       VM_READ|VM_MAYREAD|VM_PFNMAP,
                                       vdso_info[abi].dm);
        if (IS_ERR(ret))
@@ -192,7 +205,7 @@ static int __setup_additional_pages(enum vdso_abi abi,
        if (IS_ENABLED(CONFIG_ARM64_BTI_KERNEL) && system_supports_bti())
                gp_flags = VM_ARM64_BTI;
 
-       vdso_base += PAGE_SIZE;
+       vdso_base += VVAR_NR_PAGES * PAGE_SIZE;
        mm->context.vdso = (void *)vdso_base;
        ret = _install_special_mapping(mm, vdso_base, vdso_text_len,
                                       VM_READ|VM_EXEC|gp_flags|
index 7ad2d3a0cd489ab08a368cbd07df2a128b893d12..d808ad31e01f766d799449b81fb4e16c3f477157 100644 (file)
@@ -17,7 +17,10 @@ OUTPUT_ARCH(aarch64)
 
 SECTIONS
 {
-       PROVIDE(_vdso_data = . - PAGE_SIZE);
+       PROVIDE(_vdso_data = . - __VVAR_PAGES * PAGE_SIZE);
+#ifdef CONFIG_TIME_NS
+       PROVIDE(_timens_data = _vdso_data + PAGE_SIZE);
+#endif
        . = VDSO_LBASE + SIZEOF_HEADERS;
 
        .hash           : { *(.hash) }                  :text
index 337d03522048b44a82f615bccfdbbd01e77aec03..3348ce5ea306d0fc8bea1f4b178eb8a3d3bab3b9 100644 (file)
@@ -17,7 +17,10 @@ OUTPUT_ARCH(arm)
 
 SECTIONS
 {
-       PROVIDE_HIDDEN(_vdso_data = . - PAGE_SIZE);
+       PROVIDE_HIDDEN(_vdso_data = . - __VVAR_PAGES * PAGE_SIZE);
+#ifdef CONFIG_TIME_NS
+       PROVIDE_HIDDEN(_timens_data = _vdso_data + PAGE_SIZE);
+#endif
        . = VDSO_LBASE + SIZEOF_HEADERS;
 
        .hash           : { *(.hash) }                  :text
index 7955c56d6b3c331abf9652a0796f9ca39e984d8e..ee810cae4e1e4619349e8960644873385262abf3 100644 (file)
@@ -109,6 +109,7 @@ struct vdso_data {
  * relocation, and this is what we need.
  */
 extern struct vdso_data _vdso_data[CS_BASES] __attribute__((visibility("hidden")));
+extern struct vdso_data _timens_data[CS_BASES] __attribute__((visibility("hidden")));
 
 /*
  * The generic vDSO implementation requires that gettimeofday.h