public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Theodore Ts'o <tytso@mit.edu>, Arnd Bergmann <arnd@arndb.de>,
	Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	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>,
	linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	linux-arch@vger.kernel.org
Subject: Re: [PATCH] random: vDSO: Redefine PAGE_SIZE and PAGE_MASK
Date: Tue, 27 Aug 2024 10:55:32 +0200	[thread overview]
Message-ID: <cd32f64c-e3c4-46f3-94cc-69baf493f452@csgroup.eu> (raw)
In-Reply-To: <Zs2RCfMgfNu_2vos@zx2c4.com>



Le 27/08/2024 à 10:40, Jason A. Donenfeld a écrit :
> I don't love this, but it might be the lesser of evils, so sure, let's
> do it.

I don't love it either but I still prefer it to:

#ifndef PAGE_SIZE
#define PAGE_SIZE
#define PAGE_MASK
#endif

At least we are sure that every architecture get the same , independant 
of the selected options, and we know what we get.

For instance, on x86, when you select CONFIG_HYPERV_TIMER you get 
asm/hyperv_timer.h which indirectly pulls page.h. But when 
CONFIG_HYPERV_TIMER is not selected you don't get asm/hyperv_timer.h

> 
> I think I'll combine these header fixups so that the whole operation is
> a bit more clear. The commit is still pretty small. Something like
> below:

Looks good to me.

Thanks
Christophe

> 
>  From 0d9a3d68cd6222395a605abd0ac625c41d4cabfa Mon Sep 17 00:00:00 2001
> From: Christophe Leroy <christophe.leroy@csgroup.eu>
> Date: Tue, 27 Aug 2024 09:31:47 +0200
> Subject: [PATCH] random: vDSO: clean header inclusion in getrandom
> 
> Depending on the architecture, building a 32-bit vDSO on a 64-bit kernel
> is problematic when some system headers are included.
> 
> Minimise the amount of headers by moving needed items, such as
> __{get,put}_unaligned_t, into dedicated common headers and in general
> use more specific headers, similar to what was done in commit
> 8165b57bca21 ("linux/const.h: Extract common header for vDSO") and
> commit 8c59ab839f52 ("lib/vdso: Enable common headers").
> 
> On some architectures this results in missing PAGE_SIZE, as was
> described by commit 8b3843ae3634 ("vdso/datapage: Quick fix - use
> asm/page-def.h for ARM64"), so define this if necessary, in the same way
> as done prior by commit cffaefd15a8f ("vdso: Use CONFIG_PAGE_SHIFT in
> vdso/datapage.h").
> 
> Removing linux/time64.h leads to missing 'struct timespec64' in
> x86's asm/pvclock.h. Add a forward declaration of that struct in
> that file.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
>   arch/x86/include/asm/pvclock.h  |  1 +
>   include/asm-generic/unaligned.h | 11 +----------
>   include/vdso/helpers.h          |  1 +
>   include/vdso/unaligned.h        | 15 +++++++++++++++
>   lib/vdso/getrandom.c            | 13 ++++++++-----
>   5 files changed, 26 insertions(+), 15 deletions(-)
>   create mode 100644 include/vdso/unaligned.h
> 
> 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/asm-generic/unaligned.h b/include/asm-generic/unaligned.h
> index a84c64e5f11e..95acdd70b3b2 100644
> --- a/include/asm-generic/unaligned.h
> +++ b/include/asm-generic/unaligned.h
> @@ -8,16 +8,7 @@
>    */
>   #include <linux/unaligned/packed_struct.h>
>   #include <asm/byteorder.h>
> -
> -#define __get_unaligned_t(type, ptr) ({						\
> -	const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);	\
> -	__pptr->x;								\
> -})
> -
> -#define __put_unaligned_t(type, val, ptr) do {					\
> -	struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);		\
> -	__pptr->x = (val);							\
> -} while (0)
> +#include <vdso/unaligned.h>
> 
>   #define get_unaligned(ptr)	__get_unaligned_t(typeof(*(ptr)), (ptr))
>   #define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))
> 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/include/vdso/unaligned.h b/include/vdso/unaligned.h
> new file mode 100644
> index 000000000000..eee3d2a4dbe4
> --- /dev/null
> +++ b/include/vdso/unaligned.h
> @@ -0,0 +1,15 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef __VDSO_UNALIGNED_H
> +#define __VDSO_UNALIGNED_H
> +
> +#define __get_unaligned_t(type, ptr) ({						\
> +	const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);	\
> +	__pptr->x;								\
> +})
> +
> +#define __put_unaligned_t(type, val, ptr) do {					\
> +	struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);		\
> +	__pptr->x = (val);							\
> +} while (0)
> +
> +#endif /* __VDSO_UNALIGNED_H */
> diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c
> index 1281fa3546c2..938ca539aaa6 100644
> --- a/lib/vdso/getrandom.c
> +++ b/lib/vdso/getrandom.c
> @@ -4,15 +4,18 @@
>    */
> 
>   #include <linux/array_size.h>
> -#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>
> +
> +#undef PAGE_SIZE
> +#undef PAGE_MASK
> +#define PAGE_SIZE (1UL << CONFIG_PAGE_SHIFT)
> +#define PAGE_MASK (~(PAGE_SIZE - 1))
> 
>   #define MEMCPY_AND_ZERO_SRC(type, dst, src, len) do {				\
>   	while (len >= sizeof(type)) {						\
> --
> 2.46.0

  reply	other threads:[~2024-08-27  8:55 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-27  7:31 [PATCH 0/4] Fixups for random vDSO Christophe Leroy
2024-08-27  7:31 ` [PATCH 1/4] asm-generic/unaligned.h: Extract common header for vDSO Christophe Leroy
2024-08-27  7:31 ` [PATCH 2/4] random: vDSO: Don't use PAGE_SIZE and PAGE_MASK Christophe Leroy
2024-08-27  7:49   ` Jason A. Donenfeld
2024-08-27  8:16     ` Christophe Leroy
2024-08-27  8:23       ` Jason A. Donenfeld
2024-08-27  8:26   ` [PATCH] random: vDSO: Redefine " Christophe Leroy
2024-08-27  8:40     ` Jason A. Donenfeld
2024-08-27  8:55       ` Christophe Leroy [this message]
2024-08-27  9:59       ` Arnd Bergmann
2024-08-27 10:49         ` Christophe Leroy
2024-08-27 16:05           ` Vincenzo Frascino
2024-08-27 17:14             ` Christophe Leroy
2024-08-29 12:01               ` Vincenzo Frascino
2024-08-29 15:00                 ` Christophe Leroy
2024-08-29 15:34                   ` Vincenzo Frascino
2024-08-27 17:38             ` LEROY Christophe
2024-08-29 14:07               ` Vincenzo Frascino
2024-08-27  7:31 ` [PATCH 3/4] random: vDSO: Clean header inclusion in getrandom Christophe Leroy
2024-08-27  7:31 ` [PATCH 4/4] random: vDSO: don't use 64 bits atomics on 32 bits architectures Christophe Leroy
2024-08-27  8:03   ` 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=cd32f64c-e3c4-46f3-94cc-69baf493f452@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=Jason@zx2c4.com \
    --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-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --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