diff mbox series

[RFC,4/4] riscv: Introduce set_compat_task() in asm/compat.h

Message ID 20231222074605.452452-5-leobras@redhat.com (mailing list archive)
State New
Headers show
Series Introduce & Optimize compat-mode helpers | expand

Commit Message

Leonardo Bras Dec. 22, 2023, 7:46 a.m. UTC
In order to have all task compat bit access directly in compat.h, introduce
set_compat_task() to set/reset those when needed.

Also, since it's only used on an if/else scenario, simplify the macro using
it.

Signed-off-by: Leonardo Bras <leobras@redhat.com>
---
 arch/riscv/include/asm/compat.h | 8 ++++++++
 arch/riscv/include/asm/elf.h    | 5 +----
 2 files changed, 9 insertions(+), 4 deletions(-)

Comments

Guo Ren Dec. 22, 2023, 8:11 a.m. UTC | #1
On Fri, Dec 22, 2023 at 3:47 PM Leonardo Bras <leobras@redhat.com> wrote:
>
> In order to have all task compat bit access directly in compat.h, introduce
> set_compat_task() to set/reset those when needed.
>
> Also, since it's only used on an if/else scenario, simplify the macro using
> it.
>
> Signed-off-by: Leonardo Bras <leobras@redhat.com>
> ---
>  arch/riscv/include/asm/compat.h | 8 ++++++++
>  arch/riscv/include/asm/elf.h    | 5 +----
>  2 files changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/arch/riscv/include/asm/compat.h b/arch/riscv/include/asm/compat.h
> index da4b28cd01a95..aa103530a5c83 100644
> --- a/arch/riscv/include/asm/compat.h
> +++ b/arch/riscv/include/asm/compat.h
> @@ -28,6 +28,14 @@ static inline int is_compat_thread(struct thread_info *thread)
>         return test_ti_thread_flag(thread, TIF_32BIT);
>  }
>
> +static inline void set_compat_task(bool is_compat)
> +{
> +       if (is_compat)
> +               set_thread_flag(TIF_32BIT);
> +       else
> +               clear_thread_flag(TIF_32BIT);
> +}
> +
>  struct compat_user_regs_struct {
>         compat_ulong_t pc;
>         compat_ulong_t ra;
> diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h
> index 2e88257cafaea..c7aea7886d22a 100644
> --- a/arch/riscv/include/asm/elf.h
> +++ b/arch/riscv/include/asm/elf.h
> @@ -135,10 +135,7 @@ do {                                                       \
>  #ifdef CONFIG_COMPAT
>
>  #define SET_PERSONALITY(ex)                                    \
> -do {    if ((ex).e_ident[EI_CLASS] == ELFCLASS32)              \
> -               set_thread_flag(TIF_32BIT);                     \
> -       else                                                    \
> -               clear_thread_flag(TIF_32BIT);                   \
> +do {   set_compat_task((ex).e_ident[EI_CLASS] == ELFCLASS32);  \
>         if (personality(current->personality) != PER_LINUX32)   \
>                 set_personality(PER_LINUX |                     \
>                         (current->personality & (~PER_MASK)));  \
> --
> 2.43.0
>
LGTM

Reviewed-by: Guo Ren <guoren@kernel.org>
Leonardo Bras Dec. 22, 2023, 8:28 a.m. UTC | #2
On Fri, Dec 22, 2023 at 04:11:10PM +0800, Guo Ren wrote:
> On Fri, Dec 22, 2023 at 3:47 PM Leonardo Bras <leobras@redhat.com> wrote:
> >
> > In order to have all task compat bit access directly in compat.h, introduce
> > set_compat_task() to set/reset those when needed.
> >
> > Also, since it's only used on an if/else scenario, simplify the macro using
> > it.
> >
> > Signed-off-by: Leonardo Bras <leobras@redhat.com>
> > ---
> >  arch/riscv/include/asm/compat.h | 8 ++++++++
> >  arch/riscv/include/asm/elf.h    | 5 +----
> >  2 files changed, 9 insertions(+), 4 deletions(-)
> >
> > diff --git a/arch/riscv/include/asm/compat.h b/arch/riscv/include/asm/compat.h
> > index da4b28cd01a95..aa103530a5c83 100644
> > --- a/arch/riscv/include/asm/compat.h
> > +++ b/arch/riscv/include/asm/compat.h
> > @@ -28,6 +28,14 @@ static inline int is_compat_thread(struct thread_info *thread)
> >         return test_ti_thread_flag(thread, TIF_32BIT);
> >  }
> >
> > +static inline void set_compat_task(bool is_compat)
> > +{
> > +       if (is_compat)
> > +               set_thread_flag(TIF_32BIT);
> > +       else
> > +               clear_thread_flag(TIF_32BIT);
> > +}
> > +
> >  struct compat_user_regs_struct {
> >         compat_ulong_t pc;
> >         compat_ulong_t ra;
> > diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h
> > index 2e88257cafaea..c7aea7886d22a 100644
> > --- a/arch/riscv/include/asm/elf.h
> > +++ b/arch/riscv/include/asm/elf.h
> > @@ -135,10 +135,7 @@ do {                                                       \
> >  #ifdef CONFIG_COMPAT
> >
> >  #define SET_PERSONALITY(ex)                                    \
> > -do {    if ((ex).e_ident[EI_CLASS] == ELFCLASS32)              \
> > -               set_thread_flag(TIF_32BIT);                     \
> > -       else                                                    \
> > -               clear_thread_flag(TIF_32BIT);                   \
> > +do {   set_compat_task((ex).e_ident[EI_CLASS] == ELFCLASS32);  \
> >         if (personality(current->personality) != PER_LINUX32)   \
> >                 set_personality(PER_LINUX |                     \
> >                         (current->personality & (~PER_MASK)));  \
> > --
> > 2.43.0
> >
> LGTM
> 
> Reviewed-by: Guo Ren <guoren@kernel.org>

Thanks!
Leo

> 
> -- 
> Best Regards
>  Guo Ren
>
diff mbox series

Patch

diff --git a/arch/riscv/include/asm/compat.h b/arch/riscv/include/asm/compat.h
index da4b28cd01a95..aa103530a5c83 100644
--- a/arch/riscv/include/asm/compat.h
+++ b/arch/riscv/include/asm/compat.h
@@ -28,6 +28,14 @@  static inline int is_compat_thread(struct thread_info *thread)
 	return test_ti_thread_flag(thread, TIF_32BIT);
 }
 
+static inline void set_compat_task(bool is_compat)
+{
+	if (is_compat)
+		set_thread_flag(TIF_32BIT);
+	else
+		clear_thread_flag(TIF_32BIT);
+}
+
 struct compat_user_regs_struct {
 	compat_ulong_t pc;
 	compat_ulong_t ra;
diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h
index 2e88257cafaea..c7aea7886d22a 100644
--- a/arch/riscv/include/asm/elf.h
+++ b/arch/riscv/include/asm/elf.h
@@ -135,10 +135,7 @@  do {							\
 #ifdef CONFIG_COMPAT
 
 #define SET_PERSONALITY(ex)					\
-do {    if ((ex).e_ident[EI_CLASS] == ELFCLASS32)		\
-		set_thread_flag(TIF_32BIT);			\
-	else							\
-		clear_thread_flag(TIF_32BIT);			\
+do {	set_compat_task((ex).e_ident[EI_CLASS] == ELFCLASS32);	\
 	if (personality(current->personality) != PER_LINUX32)	\
 		set_personality(PER_LINUX |			\
 			(current->personality & (~PER_MASK)));	\