linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Guo Ren <guoren@kernel.org>
To: Leonardo Bras <leobras@redhat.com>
Cc: "Paul Walmsley" <paul.walmsley@sifive.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Albert Ou" <aou@eecs.berkeley.edu>,
	"Eric Biederman" <ebiederm@xmission.com>,
	"Kees Cook" <keescook@chromium.org>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Conor Dooley" <conor.dooley@microchip.com>,
	"Andy Chiu" <andy.chiu@sifive.com>,
	"Greg Ungerer" <gerg@kernel.org>,
	"Vincent Chen" <vincent.chen@sifive.com>,
	"Xiao Wang" <xiao.w.wang@intel.com>,
	"Charlie Jenkins" <charlie@rivosinc.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Alexandre Ghiti" <alexghiti@rivosinc.com>,
	"Kemeng Shi" <shikemeng@huaweicloud.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	"Qinglin Pan" <panqinglin2020@iscas.ac.cn>,
	"Greentime Hu" <greentime.hu@sifive.com>,
	"Björn Töpel" <bjorn@rivosinc.com>,
	"Clément Léger" <cleger@rivosinc.com>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [RFC PATCH 3/4] riscv: Introduce is_compat_thread() into compat.h
Date: Fri, 22 Dec 2023 19:20:36 +0800	[thread overview]
Message-ID: <CAJF2gTSdrGhAihjYSn_9u8_Yup86GgLDELZSmHnYRc5K1BESBA@mail.gmail.com> (raw)
In-Reply-To: <20231222074605.452452-4-leobras@redhat.com>

On Fri, Dec 22, 2023 at 3:47 PM Leonardo Bras <leobras@redhat.com> wrote:
>
> 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>
> ---
>  arch/riscv/include/asm/compat.h | 8 ++++++++
>  arch/riscv/kernel/ptrace.c      | 6 +++---
>  2 files changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/arch/riscv/include/asm/compat.h b/arch/riscv/include/asm/compat.h
> index 91517b51b8e27..da4b28cd01a95 100644
> --- a/arch/riscv/include/asm/compat.h
> +++ b/arch/riscv/include/asm/compat.h
> @@ -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;
We also could put this into is_compat_task().

> +
> +       return test_ti_thread_flag(thread, TIF_32BIT);
> +}
> +
>  struct compat_user_regs_struct {
>         compat_ulong_t pc;
>         compat_ulong_t ra;
> diff --git a/arch/riscv/kernel/ptrace.c b/arch/riscv/kernel/ptrace.c
> index 2afe460de16a6..f362832123616 100644
> --- a/arch/riscv/kernel/ptrace.c
> +++ b/arch/riscv/kernel/ptrace.c
> @@ -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;
>  }
> --
> 2.43.0
>
LGTM

Reviewed-by: Guo Ren <guoren@kernel.org>

-- 
Best Regards
 Guo Ren


  reply	other threads:[~2023-12-22 11:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-22  7:46 [RFC PATCH 0/4] Introduce & Optimize compat-mode helpers Leonardo Bras
2023-12-22  7:46 ` [RFC PATCH 1/4] riscv: Replace direct thread flag check with is_compat_task() Leonardo Bras
2023-12-22  7:46 ` [RFC PATCH 2/4] riscv: add compile-time test into is_compat_task() Leonardo Bras
2023-12-22  9:35   ` Guo Ren
2023-12-22 17:12     ` Leonardo Bras
2023-12-23  4:15       ` Andy Chiu
2023-12-22  7:46 ` [RFC PATCH 3/4] riscv: Introduce is_compat_thread() into compat.h Leonardo Bras
2023-12-22 11:20   ` Guo Ren [this message]
2023-12-22 17:14     ` Leonardo Bras
2023-12-23  4:25   ` Andy Chiu
     [not found]     ` <CAJ6HWG4Pe0co91-tRpV-gKoVUJkobB=uz8J-pjTvyX=Ed49u_w@mail.gmail.com>
2023-12-28  3:10       ` Andy Chiu
2023-12-22  7:46 ` [RFC PATCH 4/4] riscv: Introduce set_compat_task() in asm/compat.h Leonardo Bras
2023-12-22  8:11   ` Guo Ren
2023-12-22  8:28     ` Leonardo Bras

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=CAJF2gTSdrGhAihjYSn_9u8_Yup86GgLDELZSmHnYRc5K1BESBA@mail.gmail.com \
    --to=guoren@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alexghiti@rivosinc.com \
    --cc=andy.chiu@sifive.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=bjorn@rivosinc.com \
    --cc=charlie@rivosinc.com \
    --cc=cleger@rivosinc.com \
    --cc=conor.dooley@microchip.com \
    --cc=david@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=gerg@kernel.org \
    --cc=greentime.hu@sifive.com \
    --cc=keescook@chromium.org \
    --cc=leobras@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=oleg@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=panqinglin2020@iscas.ac.cn \
    --cc=paul.walmsley@sifive.com \
    --cc=shikemeng@huaweicloud.com \
    --cc=vincent.chen@sifive.com \
    --cc=willy@infradead.org \
    --cc=xiao.w.wang@intel.com \
    /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