diff mbox series

[RFC,v3,6/8] arm64: Add a compat syscall flag to thread_info

Message ID 20210421190207.1803139-7-amanieu@gmail.com (mailing list archive)
State New
Headers show
Series arm64: Allow 64-bit tasks to invoke compat syscalls | expand

Commit Message

Amanieu d'Antras April 21, 2021, 7:02 p.m. UTC
This flag is used by in_compat_syscall to handle compat syscalls coming
from 64-bit tasks.

Signed-off-by: Amanieu d'Antras <amanieu@gmail.com>
Co-developed-by: Ryan Houdek <Houdek.Ryan@fex-emu.org>
Signed-off-by: Ryan Houdek <Houdek.Ryan@fex-emu.org>
---
 arch/arm64/include/asm/compat.h      |  5 +++--
 arch/arm64/include/asm/elf.h         | 13 ++++++++++++-
 arch/arm64/include/asm/thread_info.h |  3 +++
 3 files changed, 18 insertions(+), 3 deletions(-)

Comments

David Laight April 22, 2021, 8:37 a.m. UTC | #1
From: Amanieu d'Antras
> Sent: 21 April 2021 20:02
> 
> This flag is used by in_compat_syscall to handle compat syscalls coming
> from 64-bit tasks.
> 
> Signed-off-by: Amanieu d'Antras <amanieu@gmail.com>
> Co-developed-by: Ryan Houdek <Houdek.Ryan@fex-emu.org>
> Signed-off-by: Ryan Houdek <Houdek.Ryan@fex-emu.org>
> ---
>  arch/arm64/include/asm/compat.h      |  5 +++--
>  arch/arm64/include/asm/elf.h         | 13 ++++++++++++-
>  arch/arm64/include/asm/thread_info.h |  3 +++
>  3 files changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h
> index a2f5001f7793..71de0ba8b160 100644
> --- a/arch/arm64/include/asm/compat.h
> +++ b/arch/arm64/include/asm/compat.h
> @@ -190,13 +190,14 @@ static inline bool is_compat_thread(struct thread_info *thread)
> 
>  static inline bool in_compat_syscall(void)
>  {
> -	return is_compat_task();
> +	return is_compat_task() ||
> +		current_thread_info()->aarch64_compat_syscall;
>  }
...

Wouldn't it be better to ensure that a 'compat_task'
always has aarch64_compat_syscall set.

If you can't do that, just replacing the '||' with '|'
will generate better code for the usual case of both
flags being clear.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Amanieu d'Antras April 22, 2021, 1:14 p.m. UTC | #2
> Wouldn't it be better to ensure that a 'compat_task'
> always has aarch64_compat_syscall set.

Good point, I'll do that in the next version of the patch.
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h
index a2f5001f7793..71de0ba8b160 100644
--- a/arch/arm64/include/asm/compat.h
+++ b/arch/arm64/include/asm/compat.h
@@ -190,13 +190,14 @@  static inline bool is_compat_thread(struct thread_info *thread)
 
 static inline bool in_compat_syscall(void)
 {
-	return is_compat_task();
+	return is_compat_task() ||
+		current_thread_info()->aarch64_compat_syscall;
 }
 #define in_compat_syscall in_compat_syscall	/* override the generic impl */
 
 static inline bool thread_in_compat_syscall(struct thread_info *thread)
 {
-	return is_compat_thread(thread);
+	return is_compat_thread(thread) || thread->aarch64_compat_syscall;
 }
 
 #else /* !CONFIG_COMPAT */
diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index e21964898d06..f4f4ffe37ee5 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -158,10 +158,20 @@  typedef struct user_fpsimd_state elf_fpregset_t;
  */
 #define ELF_PLAT_INIT(_r, load_addr)	(_r)->regs[0] = 0
 
+#ifdef CONFIG_COMPAT
+#define CLEAR_AARCH64_COMPAT_SYSCALL()				\
+({								\
+	current_thread_info()->aarch64_compat_syscall = false;	\
+})
+#else
+#define CLEAR_AARCH64_COMPAT_SYSCALL()	((void)0)
+#endif
+
 #define SET_PERSONALITY(ex)						\
 ({									\
 	clear_thread_flag(TIF_32BIT);					\
 	current->personality &= ~READ_IMPLIES_EXEC;			\
+	CLEAR_AARCH64_COMPAT_SYSCALL();					\
 })
 
 /* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */
@@ -228,7 +238,8 @@  typedef compat_elf_greg_t		compat_elf_gregset_t[COMPAT_ELF_NGREG];
 #define COMPAT_SET_PERSONALITY(ex)					\
 ({									\
 	set_thread_flag(TIF_32BIT);					\
- })
+	CLEAR_AARCH64_COMPAT_SYSCALL();					\
+})
 #ifdef CONFIG_COMPAT_VDSO
 #define COMPAT_ARCH_DLINFO						\
 do {									\
diff --git a/arch/arm64/include/asm/thread_info.h b/arch/arm64/include/asm/thread_info.h
index 6623c99f0984..756e977fc37a 100644
--- a/arch/arm64/include/asm/thread_info.h
+++ b/arch/arm64/include/asm/thread_info.h
@@ -42,6 +42,9 @@  struct thread_info {
 	void			*scs_base;
 	void			*scs_sp;
 #endif
+#ifdef CONFIG_COMPAT
+	bool			aarch64_compat_syscall;
+#endif
 };
 
 #define thread_saved_pc(tsk)	\