linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] x86: vdso: Two small ifdef cleanups
@ 2024-09-10 10:11 Thomas Weißschuh
  2024-09-10 10:11 ` [PATCH 1/2] x86: vdso: Remove ifdeffery around page setup variants Thomas Weißschuh
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2024-09-10 10:11 UTC (permalink / raw)
  To: Andy Lutomirski, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Eric Biederman, Kees Cook, Thomas Gleixner
  Cc: linux-kernel, linux-mm, Thomas Weißschuh

Some small non-functional cleanups to make the vdso setup easier to
read.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Thomas Weißschuh (2):
      x86: vdso: Remove ifdeffery around page setup variants
      x86: vdso: Remove redundant ifdeffery around in_ia32_syscall()

 arch/x86/entry/vdso/vma.c   | 35 ++++++++++++-----------------------
 arch/x86/include/asm/elf.h  |  4 ----
 arch/x86/include/asm/vdso.h |  8 --------
 3 files changed, 12 insertions(+), 35 deletions(-)
---
base-commit: bc83b4d1f08695e85e85d36f7b803da58010161d
change-id: 20240909-x86-vdso-ifdef-2bda95c8c897

Best regards,
-- 
Thomas Weißschuh <thomas.weissschuh@linutronix.de>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] x86: vdso: Remove ifdeffery around page setup variants
  2024-09-10 10:11 [PATCH 0/2] x86: vdso: Two small ifdef cleanups Thomas Weißschuh
@ 2024-09-10 10:11 ` Thomas Weißschuh
  2024-09-10 10:11 ` [PATCH 2/2] x86: vdso: Remove redundant ifdeffery around in_ia32_syscall() Thomas Weißschuh
  2025-04-22 12:25 ` [PATCH 0/2] x86: vdso: Two small ifdef cleanups Ingo Molnar
  2 siblings, 0 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2024-09-10 10:11 UTC (permalink / raw)
  To: Andy Lutomirski, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Eric Biederman, Kees Cook, Thomas Gleixner
  Cc: linux-kernel, linux-mm, Thomas Weißschuh

Replace the open-coded ifdefs in C sources files with IS_ENABLED().
This makes the code easier to read and enables the compiler to typecheck
also the disabled parts, before optimizing them away.
To make this work, also remove the ifdefs from declarations of used
variables.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 arch/x86/entry/vdso/vma.c   | 31 ++++++++++++-------------------
 arch/x86/include/asm/elf.h  |  4 ----
 arch/x86/include/asm/vdso.h |  8 --------
 3 files changed, 12 insertions(+), 31 deletions(-)

diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
index 6d83ceb7f1ba..9059b9d96393 100644
--- a/arch/x86/entry/vdso/vma.c
+++ b/arch/x86/entry/vdso/vma.c
@@ -300,7 +300,6 @@ int map_vdso_once(const struct vdso_image *image, unsigned long addr)
 	return map_vdso(image, addr);
 }
 
-#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
 static int load_vdso32(void)
 {
 	if (vdso32_enabled != 1)  /* Other values all mean "disabled" */
@@ -308,39 +307,33 @@ static int load_vdso32(void)
 
 	return map_vdso(&vdso_image_32, 0);
 }
-#endif
 
-#ifdef CONFIG_X86_64
 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
 {
-	if (!vdso64_enabled)
-		return 0;
+	if (IS_ENABLED(CONFIG_X86_64)) {
+		if (!vdso64_enabled)
+			return 0;
+
+		return map_vdso(&vdso_image_64, 0);
+	}
 
-	return map_vdso(&vdso_image_64, 0);
+	return load_vdso32();
 }
 
 #ifdef CONFIG_COMPAT
 int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
 				       int uses_interp, bool x32)
 {
-#ifdef CONFIG_X86_X32_ABI
-	if (x32) {
+	if (IS_ENABLED(CONFIG_X86_X32_ABI) && x32) {
 		if (!vdso64_enabled)
 			return 0;
 		return map_vdso(&vdso_image_x32, 0);
 	}
-#endif
-#ifdef CONFIG_IA32_EMULATION
-	return load_vdso32();
-#else
+
+	if (IS_ENABLED(CONFIG_IA32_EMULATION))
+		return load_vdso32();
+
 	return 0;
-#endif
-}
-#endif
-#else
-int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
-{
-	return load_vdso32();
 }
 #endif
 
diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
index 1fb83d47711f..d5a5dadc1cbe 100644
--- a/arch/x86/include/asm/elf.h
+++ b/arch/x86/include/asm/elf.h
@@ -75,12 +75,8 @@ typedef struct user_i387_struct elf_fpregset_t;
 
 #include <asm/vdso.h>
 
-#ifdef CONFIG_X86_64
 extern unsigned int vdso64_enabled;
-#endif
-#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
 extern unsigned int vdso32_enabled;
-#endif
 
 /*
  * This is used to ensure we don't load something for the wrong architecture.
diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
index d7f6592b74a9..3f45bcc60b4d 100644
--- a/arch/x86/include/asm/vdso.h
+++ b/arch/x86/include/asm/vdso.h
@@ -33,17 +33,9 @@ struct vdso_image {
 	long sym_vdso32_rt_sigreturn_landing_pad;
 };
 
-#ifdef CONFIG_X86_64
 extern const struct vdso_image vdso_image_64;
-#endif
-
-#ifdef CONFIG_X86_X32_ABI
 extern const struct vdso_image vdso_image_x32;
-#endif
-
-#if defined CONFIG_X86_32 || defined CONFIG_COMPAT
 extern const struct vdso_image vdso_image_32;
-#endif
 
 extern int __init init_vdso_image(const struct vdso_image *image);
 

-- 
2.46.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] x86: vdso: Remove redundant ifdeffery around in_ia32_syscall()
  2024-09-10 10:11 [PATCH 0/2] x86: vdso: Two small ifdef cleanups Thomas Weißschuh
  2024-09-10 10:11 ` [PATCH 1/2] x86: vdso: Remove ifdeffery around page setup variants Thomas Weißschuh
@ 2024-09-10 10:11 ` Thomas Weißschuh
  2024-09-10 14:34   ` Eric W. Biederman
  2025-04-22 12:25 ` [PATCH 0/2] x86: vdso: Two small ifdef cleanups Ingo Molnar
  2 siblings, 1 reply; 6+ messages in thread
From: Thomas Weißschuh @ 2024-09-10 10:11 UTC (permalink / raw)
  To: Andy Lutomirski, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Eric Biederman, Kees Cook, Thomas Gleixner
  Cc: linux-kernel, linux-mm, Thomas Weißschuh

The ifdefs only guard code that is also guarded by in_ia32_syscall(),
which already contains the same ifdefs itself.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 arch/x86/entry/vdso/vma.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
index 9059b9d96393..ab2b011471e0 100644
--- a/arch/x86/entry/vdso/vma.c
+++ b/arch/x86/entry/vdso/vma.c
@@ -75,7 +75,6 @@ static vm_fault_t vdso_fault(const struct vm_special_mapping *sm,
 static void vdso_fix_landing(const struct vdso_image *image,
 		struct vm_area_struct *new_vma)
 {
-#if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
 	if (in_ia32_syscall() && image == &vdso_image_32) {
 		struct pt_regs *regs = current_pt_regs();
 		unsigned long vdso_land = image->sym_int80_landing_pad;
@@ -86,7 +85,6 @@ static void vdso_fix_landing(const struct vdso_image *image,
 		if (regs->ip == old_land_addr)
 			regs->ip = new_vma->vm_start + vdso_land;
 	}
-#endif
 }
 
 static int vdso_mremap(const struct vm_special_mapping *sm,
@@ -339,7 +337,6 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
 
 bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs)
 {
-#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
 	const struct vdso_image *image = current->mm->context.vdso_image;
 	unsigned long vdso = (unsigned long) current->mm->context.vdso;
 
@@ -348,7 +345,6 @@ bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs)
 		    regs->ip == vdso + image->sym_vdso32_rt_sigreturn_landing_pad)
 			return true;
 	}
-#endif
 	return false;
 }
 

-- 
2.46.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] x86: vdso: Remove redundant ifdeffery around in_ia32_syscall()
  2024-09-10 10:11 ` [PATCH 2/2] x86: vdso: Remove redundant ifdeffery around in_ia32_syscall() Thomas Weißschuh
@ 2024-09-10 14:34   ` Eric W. Biederman
  2024-09-10 18:10     ` Thomas Weißschuh
  0 siblings, 1 reply; 6+ messages in thread
From: Eric W. Biederman @ 2024-09-10 14:34 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Andy Lutomirski, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Kees Cook, Thomas Gleixner, linux-kernel,
	linux-mm

Thomas Weißschuh <thomas.weissschuh@linutronix.de> writes:

> The ifdefs only guard code that is also guarded by in_ia32_syscall(),
> which already contains the same ifdefs itself.
>
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
>  arch/x86/entry/vdso/vma.c | 4 ----
>  1 file changed, 4 deletions(-)
>
> diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
> index 9059b9d96393..ab2b011471e0 100644
> --- a/arch/x86/entry/vdso/vma.c
> +++ b/arch/x86/entry/vdso/vma.c
> @@ -75,7 +75,6 @@ static vm_fault_t vdso_fault(const struct vm_special_mapping *sm,
>  static void vdso_fix_landing(const struct vdso_image *image,
>  		struct vm_area_struct *new_vma)
>  {
> -#if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
>  	if (in_ia32_syscall() && image == &vdso_image_32) {
>  		struct pt_regs *regs = current_pt_regs();
>  		unsigned long vdso_land = image->sym_int80_landing_pad;
> @@ -86,7 +85,6 @@ static void vdso_fix_landing(const struct vdso_image *image,
>  		if (regs->ip == old_land_addr)
>  			regs->ip = new_vma->vm_start + vdso_land;
>  	}
> -#endif
>  }
>  
>  static int vdso_mremap(const struct vm_special_mapping *sm,
> @@ -339,7 +337,6 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
>  
>  bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs)
>  {
> -#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
>  	const struct vdso_image *image = current->mm->context.vdso_image;
>  	unsigned long vdso = (unsigned long) current->mm->context.vdso;
>  
> @@ -348,7 +345,6 @@ bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs)
>  		    regs->ip == vdso + image->sym_vdso32_rt_sigreturn_landing_pad)
>  			return true;
>  	}
> -#endif
>  	return false;
>  }

Have you tested to verify that after this change
arch_syscall_is_vdso_signature compiles out the "image" and "vdso"
variables?

If the compilers don't it might be worth it rearrange the code as:
	if (in_ia32_syscall()) {
		const struct vdso_image *image = current->mm->context.vdso_image;
		unsigned long vdso = (unsigned long) current->mm->context.vdso;

		if (image == &vdso_image_32) {
                	....
                        return true;
                }
	}
        return false.

Making the variables depend upon in_ia32_syscall() so you can be certain
they are compiles out.

Eric



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] x86: vdso: Remove redundant ifdeffery around in_ia32_syscall()
  2024-09-10 14:34   ` Eric W. Biederman
@ 2024-09-10 18:10     ` Thomas Weißschuh
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2024-09-10 18:10 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Thomas Weißschuh, Andy Lutomirski, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Kees Cook,
	Thomas Gleixner, linux-kernel, linux-mm

Hi Eric,

On 2024-09-10 09:34:46+0000, Eric W. Biederman wrote:
> Thomas Weißschuh <thomas.weissschuh@linutronix.de> writes:
> 
> > The ifdefs only guard code that is also guarded by in_ia32_syscall(),
> > which already contains the same ifdefs itself.
> >
> > Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> > ---
> >  arch/x86/entry/vdso/vma.c | 4 ----
> >  1 file changed, 4 deletions(-)
> >
> > diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
> > index 9059b9d96393..ab2b011471e0 100644
> > --- a/arch/x86/entry/vdso/vma.c
> > +++ b/arch/x86/entry/vdso/vma.c
> > @@ -75,7 +75,6 @@ static vm_fault_t vdso_fault(const struct vm_special_mapping *sm,
> >  static void vdso_fix_landing(const struct vdso_image *image,
> >  		struct vm_area_struct *new_vma)
> >  {
> > -#if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
> >  	if (in_ia32_syscall() && image == &vdso_image_32) {
> >  		struct pt_regs *regs = current_pt_regs();
> >  		unsigned long vdso_land = image->sym_int80_landing_pad;
> > @@ -86,7 +85,6 @@ static void vdso_fix_landing(const struct vdso_image *image,
> >  		if (regs->ip == old_land_addr)
> >  			regs->ip = new_vma->vm_start + vdso_land;
> >  	}
> > -#endif
> >  }
> >  
> >  static int vdso_mremap(const struct vm_special_mapping *sm,
> > @@ -339,7 +337,6 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
> >  
> >  bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs)
> >  {
> > -#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
> >  	const struct vdso_image *image = current->mm->context.vdso_image;
> >  	unsigned long vdso = (unsigned long) current->mm->context.vdso;
> >  
> > @@ -348,7 +345,6 @@ bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs)
> >  		    regs->ip == vdso + image->sym_vdso32_rt_sigreturn_landing_pad)
> >  			return true;
> >  	}
> > -#endif
> >  	return false;
> >  }
> 
> Have you tested to verify that after this change
> arch_syscall_is_vdso_signature compiles out the "image" and "vdso"
> variables?

Yes, I did:

$ objdump --disassemble=arch_syscall_is_vdso_sigreturn arch/x86/entry/vdso/vma.o
arch/x86/entry/vdso/vma.o:     file format elf64-x86-64

Disassembly of section .text:

00000000000007f0 <arch_syscall_is_vdso_sigreturn>:
 7f0:	f3 0f 1e fa          	endbr64
 7f4:	e8 00 00 00 00       	call   7f9 <arch_syscall_is_vdso_sigreturn+0x9>
 7f9:	31 c0                	xor    %eax,%eax
 7fb:	e9 00 00 00 00       	jmp    800 <arch_syscall_is_vdso_sigreturn+0x10>


> 
> If the compilers don't it might be worth it rearrange the code as:
> 	if (in_ia32_syscall()) {
> 		const struct vdso_image *image = current->mm->context.vdso_image;
> 		unsigned long vdso = (unsigned long) current->mm->context.vdso;
> 
> 		if (image == &vdso_image_32) {
>                 	....
>                         return true;
>                 }
> 	}
>         return false.
> 
> Making the variables depend upon in_ia32_syscall() so you can be certain
> they are compiles out.

If that structure is preferred I can send a v2.


Thomas


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] x86: vdso: Two small ifdef cleanups
  2024-09-10 10:11 [PATCH 0/2] x86: vdso: Two small ifdef cleanups Thomas Weißschuh
  2024-09-10 10:11 ` [PATCH 1/2] x86: vdso: Remove ifdeffery around page setup variants Thomas Weißschuh
  2024-09-10 10:11 ` [PATCH 2/2] x86: vdso: Remove redundant ifdeffery around in_ia32_syscall() Thomas Weißschuh
@ 2025-04-22 12:25 ` Ingo Molnar
  2 siblings, 0 replies; 6+ messages in thread
From: Ingo Molnar @ 2025-04-22 12:25 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Andy Lutomirski, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Eric Biederman, Kees Cook, Thomas Gleixner,
	linux-kernel, linux-mm


* Thomas Weißschuh <thomas.weissschuh@linutronix.de> wrote:

> Some small non-functional cleanups to make the vdso setup easier to
> read.
> 
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
> Thomas Weißschuh (2):
>       x86: vdso: Remove ifdeffery around page setup variants
>       x86: vdso: Remove redundant ifdeffery around in_ia32_syscall()
> 
>  arch/x86/entry/vdso/vma.c   | 35 ++++++++++++-----------------------
>  arch/x86/include/asm/elf.h  |  4 ----
>  arch/x86/include/asm/vdso.h |  8 --------
>  3 files changed, 12 insertions(+), 35 deletions(-)

Looks like these patches fell between the cracks - I'm applying them to 
tip:x86/vdso if nobody objects.

Thanks,

	Ingo


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-04-22 12:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-10 10:11 [PATCH 0/2] x86: vdso: Two small ifdef cleanups Thomas Weißschuh
2024-09-10 10:11 ` [PATCH 1/2] x86: vdso: Remove ifdeffery around page setup variants Thomas Weißschuh
2024-09-10 10:11 ` [PATCH 2/2] x86: vdso: Remove redundant ifdeffery around in_ia32_syscall() Thomas Weißschuh
2024-09-10 14:34   ` Eric W. Biederman
2024-09-10 18:10     ` Thomas Weißschuh
2025-04-22 12:25 ` [PATCH 0/2] x86: vdso: Two small ifdef cleanups Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox