linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	Naveen N Rao <naveen@kernel.org>,
	Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	"Theodore Ts'o" <tytso@mit.edu>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	Shuah Khan <shuah@kernel.org>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org,
	linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: [PATCH v2 02/17] vdso: Clean header inclusion in getrandom
Date: Thu, 22 Aug 2024 09:13:10 +0200	[thread overview]
Message-ID: <2a081f1fff5e40f496153f8e0162fc7ec5adab2e.1724309198.git.christophe.leroy@csgroup.eu> (raw)
In-Reply-To: <cover.1724309198.git.christophe.leroy@csgroup.eu>

Building a VDSO32 on a 64 bits kernel is problematic when some
system headers are included. See commit 8c59ab839f52 ("lib/vdso:
Enable common headers") for more details.

Minimise the amount of headers by moving needed items into
dedicated common headers.

For PAGE_SIZE and PAGE_MASK, redefine them from CONFIG_PAGE_SHIFT
in the same way as commit cffaefd15a8f ("vdso: Use CONFIG_PAGE_SHIFT
in vdso/datapage.h")

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 arch/x86/include/asm/pvclock.h |  1 +
 include/vdso/helpers.h         |  1 +
 lib/vdso/getrandom.c           | 15 ++++++++-------
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/arch/x86/include/asm/pvclock.h b/arch/x86/include/asm/pvclock.h
index 0c92db84469d..6e4f8fae3ce9 100644
--- a/arch/x86/include/asm/pvclock.h
+++ b/arch/x86/include/asm/pvclock.h
@@ -5,6 +5,7 @@
 #include <asm/clocksource.h>
 #include <asm/pvclock-abi.h>
 
+struct timespec64;
 /* some helper functions for xen and kvm pv clock sources */
 u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src);
 u64 pvclock_clocksource_read_nowd(struct pvclock_vcpu_time_info *src);
diff --git a/include/vdso/helpers.h b/include/vdso/helpers.h
index 73501149439d..3ddb03bb05cb 100644
--- a/include/vdso/helpers.h
+++ b/include/vdso/helpers.h
@@ -4,6 +4,7 @@
 
 #ifndef __ASSEMBLY__
 
+#include <asm/barrier.h>
 #include <vdso/datapage.h>
 
 static __always_inline u32 vdso_read_begin(const struct vdso_data *vd)
diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c
index b230f0b10832..cab153c5f9be 100644
--- a/lib/vdso/getrandom.c
+++ b/lib/vdso/getrandom.c
@@ -3,15 +3,13 @@
  * Copyright (C) 2022-2024 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
  */
 
-#include <linux/cache.h>
-#include <linux/kernel.h>
-#include <linux/time64.h>
+#include <linux/minmax.h>
 #include <vdso/datapage.h>
 #include <vdso/getrandom.h>
+#include <vdso/unaligned.h>
 #include <asm/vdso/getrandom.h>
-#include <asm/vdso/vsyscall.h>
-#include <asm/unaligned.h>
 #include <uapi/linux/mman.h>
+#include <uapi/linux/random.h>
 
 #define MEMCPY_AND_ZERO_SRC(type, dst, src, len) do {				\
 	while (len >= sizeof(type)) {						\
@@ -23,6 +21,9 @@
 	}									\
 } while (0)
 
+#define _PAGE_SIZE (1UL << CONFIG_PAGE_SHIFT)
+#define _PAGE_MASK (~(_PAGE_SIZE - 1))
+
 static void memcpy_and_zero_src(void *dst, void *src, size_t len)
 {
 	if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) {
@@ -64,7 +65,7 @@ static __always_inline ssize_t
 __cvdso_getrandom_data(const struct vdso_rng_data *rng_info, void *buffer, size_t len,
 		       unsigned int flags, void *opaque_state, size_t opaque_len)
 {
-	ssize_t ret = min_t(size_t, INT_MAX & PAGE_MASK /* = MAX_RW_COUNT */, len);
+	ssize_t ret = min_t(size_t, INT_MAX & _PAGE_MASK /* = MAX_RW_COUNT */, len);
 	struct vgetrandom_state *state = opaque_state;
 	size_t batch_len, nblocks, orig_len = len;
 	bool in_use, have_retried = false;
@@ -82,7 +83,7 @@ __cvdso_getrandom_data(const struct vdso_rng_data *rng_info, void *buffer, size_
 	}
 
 	/* The state must not straddle a page, since pages can be zeroed at any time. */
-	if (unlikely(((unsigned long)opaque_state & ~PAGE_MASK) + sizeof(*state) > PAGE_SIZE))
+	if (unlikely(((unsigned long)opaque_state & ~_PAGE_MASK) + sizeof(*state) > _PAGE_SIZE))
 		return -EFAULT;
 
 	/* If the caller passes the wrong size, which might happen due to CRIU, fallback. */
-- 
2.44.0



  parent reply	other threads:[~2024-08-22  7:13 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-22  7:13 [PATCH v2 00/17] Wire up getrandom() vDSO implementation on powerpc Christophe Leroy
2024-08-22  7:13 ` [PATCH v2 01/17] asm-generic/unaligned.h: Extract common header for vDSO Christophe Leroy
2024-08-26  7:20   ` Jason A. Donenfeld
2024-08-26  7:32     ` Christophe Leroy
2024-08-22  7:13 ` Christophe Leroy [this message]
2024-08-26  8:07   ` [PATCH v2 02/17] vdso: Clean header inclusion in getrandom Jason A. Donenfeld
2024-08-26  8:37     ` Christophe Leroy
2024-08-26  8:58       ` Jason A. Donenfeld
2024-08-26 10:45         ` Christophe Leroy
2024-08-26 13:17           ` Jason A. Donenfeld
2024-08-26 13:24           ` Thomas Gleixner
2024-08-22  7:13 ` [PATCH v2 03/17] vdso: Add __arch_get_k_vdso_rng_data() Christophe Leroy
2024-08-26  7:24   ` Jason A. Donenfeld
2024-08-22  7:13 ` [PATCH v2 04/17] vdso: Add missing c-getrandom-y in Makefile Christophe Leroy
2024-08-26  7:40   ` Jason A. Donenfeld
2024-08-22  7:13 ` [PATCH v2 05/17] vdso: Avoid call to memset() by getrandom Christophe Leroy
2024-08-26  8:01   ` Jason A. Donenfeld
2024-08-27 18:08   ` Eric Biggers
2024-08-27 18:22     ` Jason A. Donenfeld
2024-08-27 22:53     ` Segher Boessenkool
2024-08-28 11:18       ` Jason A. Donenfeld
2024-08-28 12:24         ` Arnd Bergmann
2024-08-28 12:26           ` Jason A. Donenfeld
2024-08-28 12:51             ` Segher Boessenkool
2024-08-28 12:45           ` Segher Boessenkool
2024-08-28 15:40             ` Ard Biesheuvel
2024-08-28 16:20               ` Segher Boessenkool
2024-08-28 17:12                 ` Ard Biesheuvel
2024-08-28 17:25                   ` Segher Boessenkool
2024-08-29 17:36                     ` Christophe Leroy
2024-08-29 18:02                       ` Segher Boessenkool
2024-08-29 18:50                         ` Christophe Leroy
2024-08-30 10:01                         ` Michael Ellerman
2024-08-28 12:33         ` Segher Boessenkool
2024-08-28 12:51           ` Jason A. Donenfeld
2024-08-22  7:13 ` [PATCH v2 06/17] vdso: Change getrandom's generation to unsigned long Christophe Leroy
2024-08-26  7:50   ` Jason A. Donenfeld
2024-08-26  8:01     ` Christophe Leroy
2024-08-26  8:16       ` Jason A. Donenfeld
2024-08-26  9:43       ` Thomas Gleixner
2024-08-26  9:48         ` Jason A. Donenfeld
2024-08-26 10:20         ` LEROY Christophe
2024-08-22  7:13 ` [PATCH v2 07/17] mm: Define VM_DROPPABLE for powerpc/32 Christophe Leroy
2024-08-26  9:53   ` kernel test robot
2024-08-26 10:13   ` kernel test robot
2024-08-26 21:34   ` kernel test robot
2024-08-22  7:13 ` [PATCH v2 08/17] powerpc: Add little endian variants of LWZX_BE and STWX_BE Christophe Leroy
2024-08-22  7:13 ` [PATCH v2 09/17] powerpc/vdso32: Add crtsavres Christophe Leroy
2024-08-22  7:13 ` [PATCH v2 10/17] powerpc/vdso: Refactor CFLAGS for CVDSO build Christophe Leroy
2024-08-22  7:13 ` [PATCH v2 11/17] powerpc/vdso: Wire up getrandom() vDSO implementation Christophe Leroy
2024-08-22  7:13 ` [PATCH v2 12/17] selftests: vdso: Fix powerpc64 vdso_config Christophe Leroy
2024-08-22  7:13 ` [PATCH v2 13/17] selftests: vdso: Don't hard-code location of vDSO sources Christophe Leroy
2024-08-26  7:26   ` Jason A. Donenfeld
2024-08-22  7:13 ` [PATCH v2 14/17] selftests: vdso: Make test_vdso_getrandom look for the right vDSO function Christophe Leroy
2024-08-26  7:28   ` Jason A. Donenfeld
2024-08-26  7:35     ` LEROY Christophe
2024-08-22  7:13 ` [PATCH v2 15/17] selftests: vdso: Fix build of test_vdso_chacha Christophe Leroy
2024-08-26  7:33   ` Jason A. Donenfeld
2024-08-22  7:13 ` [PATCH v2 16/17] selftests: vdso: Make VDSO function call more generic Christophe Leroy
2024-08-26  7:37   ` Jason A. Donenfeld
2024-08-26  7:48     ` LEROY Christophe
2024-08-22  7:13 ` [PATCH v2 17/17] selftests: vdso: Add support for vdso_test_random for powerpc Christophe Leroy
2024-08-26  7:19 ` [PATCH v2 00/17] Wire up getrandom() vDSO implementation on powerpc Jason A. Donenfeld
2024-08-26  8:23   ` Jason A. Donenfeld

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=2a081f1fff5e40f496153f8e0162fc7ec5adab2e.1724309198.git.christophe.leroy@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=Jason@zx2c4.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=luto@kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=mpe@ellerman.id.au \
    --cc=naveen@kernel.org \
    --cc=npiggin@gmail.com \
    --cc=rostedt@goodmis.org \
    --cc=shuah@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tytso@mit.edu \
    --cc=vincenzo.frascino@arm.com \
    --cc=x86@kernel.org \
    /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