]> xenbits.xensource.com Git - people/aperard/linux.git/commitdiff
riscv: Introduce is_compat_thread() into compat.h
authorLeonardo Bras <leobras@redhat.com>
Wed, 3 Jan 2024 16:00:22 +0000 (13:00 -0300)
committerPalmer Dabbelt <palmer@rivosinc.com>
Tue, 19 Mar 2024 23:39:39 +0000 (16:39 -0700)
task_user_regset_view() makes use of a function very similar to
is_compat_task(), but pointing to a any thread.

In arm64 asm/compat.h there is a function very similar to that:
is_compat_thread(struct thread_info *thread)

Copy this function to riscv asm/compat.h and make use of it into
task_user_regset_view().

Also, introduce a compile-time test for CONFIG_COMPAT and simplify the
function code by removing the #ifdef.

Signed-off-by: Leonardo Bras <leobras@redhat.com>
Reviewed-by: Guo Ren <guoren@kernel.org>
Reviewed-by: Andy Chiu <andy.chiu@sifive.com>
Link: https://lore.kernel.org/r/20240103160024.70305-6-leobras@redhat.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/include/asm/compat.h
arch/riscv/kernel/ptrace.c

index 91517b51b8e273c632848ebb4a1b722165c64f80..da4b28cd01a9563f47cf1b4af4bf2cd57764feec 100644 (file)
@@ -20,6 +20,14 @@ static inline int is_compat_task(void)
        return test_thread_flag(TIF_32BIT);
 }
 
+static inline int is_compat_thread(struct thread_info *thread)
+{
+       if (!IS_ENABLED(CONFIG_COMPAT))
+               return 0;
+
+       return test_ti_thread_flag(thread, TIF_32BIT);
+}
+
 struct compat_user_regs_struct {
        compat_ulong_t pc;
        compat_ulong_t ra;
index 2afe460de16a62ba21cf3c7db4a96c5ec8f7d3a5..f36283212361603118e9941666c077a47a74f96a 100644 (file)
@@ -374,14 +374,14 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
 
        return ret;
 }
+#else
+static const struct user_regset_view compat_riscv_user_native_view = {};
 #endif /* CONFIG_COMPAT */
 
 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
 {
-#ifdef CONFIG_COMPAT
-       if (test_tsk_thread_flag(task, TIF_32BIT))
+       if (is_compat_thread(&task->thread_info))
                return &compat_riscv_user_native_view;
        else
-#endif
                return &riscv_user_native_view;
 }