Skip to content

Commit 550a77a

Browse files
0x7f454c46KAGA-KOKO
authored andcommitted
x86/vdso: Add time napespace page
To support time namespaces in the VDSO with a minimal impact on regular non time namespace affected tasks, the namespace handling needs to be hidden in a slow path. The most obvious place is vdso_seq_begin(). 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. Allocate the time namespace page among VVAR pages and place vdso_data on it. Provide __arch_get_timens_vdso_data() helper for VDSO code to get the code-relative position of VVARs on that special page. Co-developed-by: Andrei Vagin <avagin@openvz.org> Signed-off-by: Andrei Vagin <avagin@openvz.org> Signed-off-by: Dmitry Safonov <dima@arista.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20191112012724.250792-23-dima@arista.com
1 parent 64b302a commit 550a77a

6 files changed

Lines changed: 26 additions & 3 deletions

File tree

‎arch/x86/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ config X86
124124
select GENERIC_STRNLEN_USER
125125
select GENERIC_TIME_VSYSCALL
126126
select GENERIC_GETTIMEOFDAY
127+
select GENERIC_VDSO_TIME_NS
127128
select GUP_GET_PTE_LOW_HIGH if X86_PAE
128129
select HARDLOCKUP_CHECK_TIMESTAMP if X86_64
129130
select HAVE_ACPI_APEI if ACPI

‎arch/x86/entry/vdso/vdso-layout.lds.S‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ SECTIONS
1616
* segment.
1717
*/
1818

19-
vvar_start = . - 3 * PAGE_SIZE;
20-
vvar_page = vvar_start;
19+
vvar_start = . - 4 * PAGE_SIZE;
20+
vvar_page = vvar_start;
2121

2222
/* Place all vvars at the offsets in asm/vvar.h. */
2323
#define EMIT_VVAR(name, offset) vvar_ ## name = vvar_page + offset;
@@ -26,6 +26,13 @@ SECTIONS
2626

2727
pvclock_page = vvar_start + PAGE_SIZE;
2828
hvclock_page = vvar_start + 2 * PAGE_SIZE;
29+
timens_page = vvar_start + 3 * PAGE_SIZE;
30+
31+
#undef _ASM_X86_VVAR_H
32+
/* Place all vvars in timens too at the offsets in asm/vvar.h. */
33+
#define EMIT_VVAR(name, offset) timens_ ## name = timens_page + offset;
34+
#include <asm/vvar.h>
35+
#undef EMIT_VVAR
2936

3037
. = SIZEOF_HEADERS;
3138

‎arch/x86/entry/vdso/vdso2c.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ enum {
7575
sym_vvar_page,
7676
sym_pvclock_page,
7777
sym_hvclock_page,
78+
sym_timens_page,
7879
};
7980

8081
const int special_pages[] = {
8182
sym_vvar_page,
8283
sym_pvclock_page,
8384
sym_hvclock_page,
85+
sym_timens_page,
8486
};
8587

8688
struct vdso_sym {
@@ -93,6 +95,7 @@ struct vdso_sym required_syms[] = {
9395
[sym_vvar_page] = {"vvar_page", true},
9496
[sym_pvclock_page] = {"pvclock_page", true},
9597
[sym_hvclock_page] = {"hvclock_page", true},
98+
[sym_timens_page] = {"timens_page", true},
9699
{"VDSO32_NOTE_MASK", true},
97100
{"__kernel_vsyscall", true},
98101
{"__kernel_sigreturn", true},

‎arch/x86/include/asm/vdso.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct vdso_image {
2121
long sym_vvar_page;
2222
long sym_pvclock_page;
2323
long sym_hvclock_page;
24+
long sym_timens_page;
2425
long sym_VDSO32_NOTE_MASK;
2526
long sym___kernel_sigreturn;
2627
long sym___kernel_rt_sigreturn;

‎arch/x86/include/asm/vdso/gettimeofday.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <clocksource/hyperv_timer.h>
2222

2323
#define __vdso_data (VVAR(_vdso_data))
24+
#define __timens_vdso_data (TIMENS(_vdso_data))
2425

2526
#define VDSO_HAS_TIME 1
2627

@@ -56,6 +57,13 @@ extern struct ms_hyperv_tsc_page hvclock_page
5657
__attribute__((visibility("hidden")));
5758
#endif
5859

60+
#ifdef CONFIG_TIME_NS
61+
static __always_inline const struct vdso_data *__arch_get_timens_vdso_data(void)
62+
{
63+
return __timens_vdso_data;
64+
}
65+
#endif
66+
5967
#ifndef BUILD_VDSO32
6068

6169
static __always_inline

‎arch/x86/include/asm/vvar.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ extern char __vvar_page;
3333

3434
#define DECLARE_VVAR(offset, type, name) \
3535
extern type vvar_ ## name[CS_BASES] \
36-
__attribute__((visibility("hidden")));
36+
__attribute__((visibility("hidden"))); \
37+
extern type timens_ ## name[CS_BASES] \
38+
__attribute__((visibility("hidden"))); \
3739

3840
#define VVAR(name) (vvar_ ## name)
41+
#define TIMENS(name) (timens_ ## name)
3942

4043
#define DEFINE_VVAR(type, name) \
4144
type name[CS_BASES] \

0 commit comments

Comments
 (0)