mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eric Curtin <ericcurtin17@gmail.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Eric Curtin <eric.curtin@docker.com>,
	Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@kernel.org>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH v2 37/43] vdso: Lay out the data pages in VDSO_PAGE_SIZE units
Date: Tue,  1 Dec 2026 01:52:09 +0000	[thread overview]
Message-ID: <20261201015240.1017259-38-ericcurtin17@gmail.com> (raw)
In-Reply-To: <20261201015240.1017259-1-ericcurtin17@gmail.com>

From: Eric Curtin <eric.curtin@docker.com>

The vDSO is built with CONFIG_PAGE_SHIFT, so the data page layout it
uses can differ from the runtime PAGE_SIZE when the page size is chosen
at boot. The kernel side must lay out and map the data pages exactly as
the vDSO code expects.

Add VDSO_PAGE_SHIFT and VDSO_PAGE_SIZE, defined from CONFIG_PAGE_SHIFT,
and use them for the vDSO data layout: the VDSO_ARCH_DATA_* sizes, the
vdso_u_* symbol offsets, vdso_initdata, the vvar mapping length, and the
timens page offsets in gettimeofday.c. Indexes of the vDSO data pages
are converted to PAGE_SIZE page offsets with the new VDSO_PGOFF() macro
when addressing vdso_data_pages, and vvar_fault() shifts the faulting
page offset back to a vDSO data page index. The static assertions on
the size of struct vdso_time_data and struct vdso_rng_data use
PAGE_SIZE_MIN.

For a compile-time page size VDSO_PAGE_SIZE equals PAGE_SIZE and the
layout does not change.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit a870d11aaf0fbcb9e4c7d19f8169832cc676b685)
---
 include/vdso/datapage.h | 10 +++++-----
 include/vdso/page.h     |  4 ++++
 lib/vdso/datastore.c    | 34 +++++++++++++++++++---------------
 lib/vdso/gettimeofday.c |  4 ++--
 4 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/include/vdso/datapage.h b/include/vdso/datapage.h
index 09897f76ae07..d999f10032b6 100644
--- a/include/vdso/datapage.h
+++ b/include/vdso/datapage.h
@@ -164,8 +164,8 @@ extern struct vdso_time_data *vdso_k_time_data;
 extern struct vdso_rng_data *vdso_k_rng_data;
 extern struct vdso_arch_data *vdso_k_arch_data;
 
-#define VDSO_ARCH_DATA_SIZE ALIGN(sizeof(struct vdso_arch_data), PAGE_SIZE)
-#define VDSO_ARCH_DATA_PAGES (VDSO_ARCH_DATA_SIZE >> PAGE_SHIFT)
+#define VDSO_ARCH_DATA_SIZE ALIGN(sizeof(struct vdso_arch_data), VDSO_PAGE_SIZE)
+#define VDSO_ARCH_DATA_PAGES (VDSO_ARCH_DATA_SIZE >> VDSO_PAGE_SHIFT)
 
 enum vdso_pages {
 	VDSO_TIME_PAGE_OFFSET,
@@ -179,19 +179,19 @@ enum vdso_pages {
 #else /* !__ASSEMBLER__ */
 
 #ifdef CONFIG_VDSO_GETRANDOM
-#define __vdso_u_rng_data	PROVIDE(vdso_u_rng_data = vdso_u_data + 2 * PAGE_SIZE);
+#define __vdso_u_rng_data	PROVIDE(vdso_u_rng_data = vdso_u_data + 2 * VDSO_PAGE_SIZE);
 #else
 #define __vdso_u_rng_data
 #endif
 
 #ifdef CONFIG_ARCH_HAS_VDSO_ARCH_DATA
-#define __vdso_u_arch_data	PROVIDE(vdso_u_arch_data = vdso_u_data + 3 * PAGE_SIZE);
+#define __vdso_u_arch_data	PROVIDE(vdso_u_arch_data = vdso_u_data + 3 * VDSO_PAGE_SIZE);
 #else
 #define __vdso_u_arch_data
 #endif
 
 #define VDSO_VVAR_SYMS						\
-	PROVIDE(vdso_u_data = . - __VDSO_PAGES * PAGE_SIZE);	\
+	PROVIDE(vdso_u_data = . - __VDSO_PAGES * VDSO_PAGE_SIZE);\
 	PROVIDE(vdso_u_time_data = vdso_u_data);		\
 	__vdso_u_rng_data					\
 	__vdso_u_arch_data					\
diff --git a/include/vdso/page.h b/include/vdso/page.h
index bc47186c07fc..b79e1c8c8363 100644
--- a/include/vdso/page.h
+++ b/include/vdso/page.h
@@ -14,6 +14,10 @@
 
 #define PAGE_SIZE	(_AC(1,UL) << CONFIG_PAGE_SHIFT)
 
+/* Granule of the vDSO data layout; constant even with boot-time PAGE_SIZE. */
+#define VDSO_PAGE_SHIFT	CONFIG_PAGE_SHIFT
+#define VDSO_PAGE_SIZE	(_AC(1,UL) << VDSO_PAGE_SHIFT)
+
 #if !defined(CONFIG_64BIT)
 /*
  * Applies only to 32-bit architectures.
diff --git a/lib/vdso/datastore.c b/lib/vdso/datastore.c
index 1426bf4e0c12..74ad8d71f6c8 100644
--- a/lib/vdso/datastore.c
+++ b/lib/vdso/datastore.c
@@ -8,32 +8,35 @@
 #include <linux/vdso_datastore.h>
 #include <vdso/datapage.h>
 
-static u8 vdso_initdata[VDSO_NR_PAGES * PAGE_SIZE] __aligned(PAGE_SIZE) __initdata = {};
+/* Convert a vDSO data page index to a PAGE_SIZE page offset. */
+#define VDSO_PGOFF(i)	((unsigned long)(i) << (VDSO_PAGE_SHIFT - PAGE_SHIFT))
+
+static u8 vdso_initdata[VDSO_NR_PAGES * VDSO_PAGE_SIZE] __aligned(VDSO_PAGE_SIZE) __initdata = {};
 
 #ifdef CONFIG_GENERIC_GETTIMEOFDAY
 struct vdso_time_data *vdso_k_time_data __ro_after_init =
-	(void *)&vdso_initdata[VDSO_TIME_PAGE_OFFSET * PAGE_SIZE];
+	(void *)&vdso_initdata[VDSO_TIME_PAGE_OFFSET * VDSO_PAGE_SIZE];
 
-static_assert(sizeof(struct vdso_time_data) <= PAGE_SIZE);
+static_assert(sizeof(struct vdso_time_data) <= PAGE_SIZE_MIN);
 #endif /* CONFIG_GENERIC_GETTIMEOFDAY */
 
 #ifdef CONFIG_VDSO_GETRANDOM
 struct vdso_rng_data *vdso_k_rng_data __ro_after_init =
-	(void *)&vdso_initdata[VDSO_RNG_PAGE_OFFSET * PAGE_SIZE];
+	(void *)&vdso_initdata[VDSO_RNG_PAGE_OFFSET * VDSO_PAGE_SIZE];
 
-static_assert(sizeof(struct vdso_rng_data) <= PAGE_SIZE);
+static_assert(sizeof(struct vdso_rng_data) <= PAGE_SIZE_MIN);
 #endif /* CONFIG_VDSO_GETRANDOM */
 
 #ifdef CONFIG_ARCH_HAS_VDSO_ARCH_DATA
 struct vdso_arch_data *vdso_k_arch_data __ro_after_init =
-	(void *)&vdso_initdata[VDSO_ARCH_PAGES_START * PAGE_SIZE];
+	(void *)&vdso_initdata[VDSO_ARCH_PAGES_START * VDSO_PAGE_SIZE];
 #endif /* CONFIG_ARCH_HAS_VDSO_ARCH_DATA */
 
 static struct page *vdso_data_pages __ro_after_init;
 
 void __init vdso_setup_data_pages(void)
 {
-	unsigned int order = get_order(VDSO_NR_PAGES * PAGE_SIZE);
+	unsigned int order = get_order(VDSO_NR_PAGES * VDSO_PAGE_SIZE);
 
 	/*
 	 * Allocate the data pages dynamically. SPARC does not support mapping
@@ -51,16 +54,16 @@ void __init vdso_setup_data_pages(void)
 	split_page(vdso_data_pages, order);
 
 	/* Move the data already written by other subsystems to the new pages */
-	memcpy(page_address(vdso_data_pages), vdso_initdata, VDSO_NR_PAGES * PAGE_SIZE);
+	memcpy(page_address(vdso_data_pages), vdso_initdata, VDSO_NR_PAGES * VDSO_PAGE_SIZE);
 
 	if (IS_ENABLED(CONFIG_GENERIC_GETTIMEOFDAY))
-		vdso_k_time_data = page_address(vdso_data_pages + VDSO_TIME_PAGE_OFFSET);
+		vdso_k_time_data = page_address(vdso_data_pages + VDSO_PGOFF(VDSO_TIME_PAGE_OFFSET));
 
 	if (IS_ENABLED(CONFIG_VDSO_GETRANDOM))
-		vdso_k_rng_data = page_address(vdso_data_pages + VDSO_RNG_PAGE_OFFSET);
+		vdso_k_rng_data = page_address(vdso_data_pages + VDSO_PGOFF(VDSO_RNG_PAGE_OFFSET));
 
 	if (IS_ENABLED(CONFIG_ARCH_HAS_VDSO_ARCH_DATA))
-		vdso_k_arch_data = page_address(vdso_data_pages + VDSO_ARCH_PAGES_START);
+		vdso_k_arch_data = page_address(vdso_data_pages + VDSO_PGOFF(VDSO_ARCH_PAGES_START));
 }
 
 static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
@@ -74,7 +77,8 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
 	page = vdso_data_pages + vmf->pgoff;
 	timens_page = find_timens_vvar_page(vma);
 
-	switch (vmf->pgoff) {
+	/* Only the first page of each vDSO data page holds data. */
+	switch (vmf->pgoff >> (VDSO_PAGE_SHIFT - PAGE_SHIFT)) {
 	case VDSO_TIME_PAGE_OFFSET:
 		if (!IS_ENABLED(CONFIG_GENERIC_GETTIMEOFDAY) || !timens_page)
 			break;
@@ -85,7 +89,7 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
 		unsigned long addr;
 		vm_fault_t err;
 
-		addr = vmf->address + VDSO_TIMENS_PAGE_OFFSET * PAGE_SIZE;
+		addr = vmf->address + VDSO_TIMENS_PAGE_OFFSET * VDSO_PAGE_SIZE;
 		err = vmf_insert_page(vma, addr, page);
 		if (unlikely(err & VM_FAULT_ERROR))
 			return err;
@@ -101,7 +105,7 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
 		 */
 		if (!IS_ENABLED(CONFIG_TIME_NS) || !timens_page)
 			break;
-		page = vdso_data_pages + VDSO_TIME_PAGE_OFFSET;
+		page = vdso_data_pages + VDSO_PGOFF(VDSO_TIME_PAGE_OFFSET);
 		break;
 	case VDSO_RNG_PAGE_OFFSET:
 	case VDSO_ARCH_PAGES_START ... VDSO_ARCH_PAGES_END:
@@ -122,7 +126,7 @@ const struct vm_special_mapping vdso_vvar_mapping = {
 
 struct vm_area_struct *vdso_install_vvar_mapping(struct mm_struct *mm, unsigned long addr)
 {
-	return _install_special_mapping(mm, addr, VDSO_NR_PAGES * PAGE_SIZE,
+	return _install_special_mapping(mm, addr, VDSO_NR_PAGES * VDSO_PAGE_SIZE,
 					VM_READ | VM_MAYREAD | VM_DONTDUMP |
 					VM_MIXEDMAP | VM_SEALED_SYSMAP,
 					&vdso_vvar_mapping);
diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c
index a324b2f2ec6c..e3ea7df41fe4 100644
--- a/lib/vdso/gettimeofday.c
+++ b/lib/vdso/gettimeofday.c
@@ -136,13 +136,13 @@ bool vdso_get_timestamp(const struct vdso_time_data *vd, const struct vdso_clock
 static __always_inline
 const struct vdso_time_data *vdso_timens_data(const struct vdso_time_data *vd)
 {
-	return (void *)vd + PAGE_SIZE;
+	return (void *)vd + VDSO_PAGE_SIZE;
 }
 
 static __always_inline
 const struct vdso_clock *vdso_timens_clock(const struct vdso_clock *vc)
 {
-	return (void *)vc + PAGE_SIZE;
+	return (void *)vc + VDSO_PAGE_SIZE;
 }
 
 static __always_inline

  parent reply	other threads:[~2026-12-01  1:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 01/43] mm: Add macros ahead of supporting boot-time page size selection Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 02/43] vmlinux.lds: Align page-aligned sections to PAGE_SIZE_MAX Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 05/43] mm: Avoid split pmd ptl if pmd level is run-time folded Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 06/43] mm/vmstat: Use THREAD_SIZE_MAX for the KSTACK_* counters Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 07/43] fork: Permit boot-time THREAD_SIZE determination Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 11/43] perf/core: Handle a boot-time PAGE_SIZE in format attrs and mlock Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 16/43] arm64: Introduce macros required for boot-time page size selection Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 21/43] arm64: Test PAGE_SIZE instead of CONFIG_ARM64_*K_PAGES Eric Curtin
2026-12-01  1:52 ` Eric Curtin [this message]
2026-12-01  1:52 ` [RFC PATCH v2 39/43] crash: Size the vmcoreinfo page array for the smallest page size Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 41/43] exit: Use THREAD_SIZE_MAX for lowest_to_date Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 42/43] tracing: Use PAGE_SIZE_MIN/MAX in the uprobe check and undefsyms page Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 43/43] arm64: Enable boot-time page size selection Eric Curtin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201015240.1017259-38-ericcurtin17@gmail.com \
    --to=ericcurtin17@gmail.com \
    --cc=eric.curtin@docker.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=tglx@kernel.org \
    --cc=vincenzo.frascino@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®