From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA042C3DA6E for ; Sat, 23 Dec 2023 04:26:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 509286B007E; Fri, 22 Dec 2023 23:26:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B8FF6B0080; Fri, 22 Dec 2023 23:26:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 380D96B0081; Fri, 22 Dec 2023 23:26:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2A04A6B007E for ; Fri, 22 Dec 2023 23:26:00 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 087C81C1590 for ; Sat, 23 Dec 2023 04:26:00 +0000 (UTC) X-FDA: 81596795280.30.0E6FF5F Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by imf12.hostedemail.com (Postfix) with ESMTP id 2332140005 for ; Sat, 23 Dec 2023 04:25:57 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=iTAoUUEv; spf=pass (imf12.hostedemail.com: domain of andy.chiu@sifive.com designates 209.85.167.45 as permitted sender) smtp.mailfrom=andy.chiu@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703305558; a=rsa-sha256; cv=none; b=cNIlFOFr9b+HrzobVKeSOZqGkv8a2peq61WY5/ymF8eKhEbPT6DETwc4Xhb2Q9D3NUXCwz H9iHgDniJGO5GzodBxGEGg+w7f8ilfT7Av0gShXU7OvCHOvJGPI4t74t7F02AAQwYSfP08 wxkFZj6d54pMj2y9CW2x7I2emqyZHzA= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=iTAoUUEv; spf=pass (imf12.hostedemail.com: domain of andy.chiu@sifive.com designates 209.85.167.45 as permitted sender) smtp.mailfrom=andy.chiu@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703305558; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Oh1r+51kM+XQXoePZoBYVvIPaqSuNTim190BEuHTp1w=; b=4SSVEv1muIJdWIZqYKw8DC1/g3oEc/YmHLhfdJeN4OLXnuSzTM7s5RbtarXqVBEJ7whio2 neehfaiCdKF8AdrdHmNFYCvqu4IH+LzXfwbPsTHfWRH9u/RZsWGukAQ1D7HWTti5Ysgiq8 qAIR8hHBu5jczo6GS/8BWqjBFy5/Ook= Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-50e1112b95cso2662397e87.0 for ; Fri, 22 Dec 2023 20:25:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1703305556; x=1703910356; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Oh1r+51kM+XQXoePZoBYVvIPaqSuNTim190BEuHTp1w=; b=iTAoUUEvibzbG8CQ5z709EMInWi4/CazvSfrGXGBDllw0WFomPWcDzv6V6P5NQR0oI e7w+BEvYLcpWCfQIB03ApXzDHlCR3l/KvfPaIP0ST4yLPvT7VzC6gEUXBV23fUFNG6Jg /25dupnvhP1vLegYIWdkRmbFsDxRMlAvqIj4G3JNvNHXjf2xEbo+jzpaI3YK00fprFwj 2+ByVWzQhTal7GuHfePtadUsgBsNqphY8+hWHbAaywEs6dq0X5SQxvXpLRwUUZiWTybd 30EEWjQaM6EEzsgIGwafpTOsw6b9dIx28COm3bqKIPY3CNF+nwXLPfywuUMfToW55C+y 0taA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703305556; x=1703910356; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Oh1r+51kM+XQXoePZoBYVvIPaqSuNTim190BEuHTp1w=; b=bJkYOKT37jwDGtjsBGq4vsekbx2EAqXKp2/IKiiWmB0LHbQ4rD29W0AYXsDssUVTWO D5AdZ5rMDDxNFyUM3cRhO+OErH7eauk3Se89a7h9BNVhC1N+QOpKKOivPgj5D0aHxr4T 7Vj9xH4BQ+WFXXfF4MI4BAbu5VRdq+MKKR1GjBXLb1DHRfO1Rv0o1yKm0HI0/aOqrjHi GUmVwfz6a856J3A3d5euNyksnEgJLT19Fcva4DQkmMqMN2GH2syFsd9OcKwpamj6vLPU URsl6qznenSoTOVi7XkoefX0s+503lo+tPcwhl+UlI2AufBlTY0muwG+nAnvKzcmVXt6 +mKg== X-Gm-Message-State: AOJu0YzjVT/jMJGTl9JoeBPURaUAMxirvH2exPJmlbZpG7AwzwBIcQIC iP3IQtkEbW/ze/VPSYKQ+t8Kf3iIt4mWJNH8FOYlcoztteemcQ== X-Google-Smtp-Source: AGHT+IFU3Q6ZEG+67oRWk4/KqL1ZNE9mgkQzAdPAehzdj9SVKh47NEVRI4+S5DVshfifQlG9dZi7NeI4A7pFy9IUZ7I= X-Received: by 2002:a19:5f14:0:b0:50e:6f20:8e40 with SMTP id t20-20020a195f14000000b0050e6f208e40mr298244lfb.207.1703305556174; Fri, 22 Dec 2023 20:25:56 -0800 (PST) MIME-Version: 1.0 References: <20231222074605.452452-1-leobras@redhat.com> <20231222074605.452452-4-leobras@redhat.com> In-Reply-To: <20231222074605.452452-4-leobras@redhat.com> From: Andy Chiu Date: Sat, 23 Dec 2023 12:25:44 +0800 Message-ID: Subject: Re: [RFC PATCH 3/4] riscv: Introduce is_compat_thread() into compat.h To: Leonardo Bras Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Eric Biederman , Kees Cook , Oleg Nesterov , Conor Dooley , Greg Ungerer , Vincent Chen , Xiao Wang , Charlie Jenkins , Andrew Morton , Alexandre Ghiti , Kemeng Shi , David Hildenbrand , "Matthew Wilcox (Oracle)" , Qinglin Pan , Greentime Hu , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= , Guo Ren , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 2332140005 X-Stat-Signature: ia4soksiq1pg6aof8myfbodrasrehpgm X-Rspam-User: X-HE-Tag: 1703305557-836838 X-HE-Meta: U2FsdGVkX18bTxnvQjnpouH2PN2EbK9fxCbh3bLY/KDj3xg+GaGWLP5aecvHxgGVR6QE3xBtrugW8oeOHgAc8ZmiPR4tsKgNQA4qPCCgY921NC44G78kpm3NBMxRx9IFhZKv5t7UHlT05d3Dj9npikDVXKtkcwab5zZvEtHPnSuo/PBu1sbIQlseVvhkRKH8+5YVE74ZYHJLQdlQWEhYAAAyMWdLWDbrztAlBdvpFNMi6D6m/dOxnxDSstY1H0d4AChZCHSWq/HZVVI2f/lH/Q6niL14omqtCA7etYNtox2m5xyRvAfLdkgy+lF5FlXp3TBT5qTK5uc45lI8Bp2EXRH13T54ksRvox6ssvls5kRd2RI+izUuDLxfuscGJRbODW1fIwYt8uqbT+ZdOrzTx//Jjt4V8KLy42QcYrKjkeE9c/GReuKYSDhYHcNNHiRvozaw33041tBeZKiYJkbAvfJsO2taUvimZjrQcGTEfpezLiqeYqXTA465HWAQ9xNlPLcP2SPMKyfMtJWqAPkhZJzOn2HR5Hfst9A6t8yxn2nZdFfF0bbzkT3ZngQ/mpL5jyyEpanB0oAp9oNS+ZjiyBWffypAE+yXTAzQn+B5ne55OyZhWPHDB4Sw2mF37czuk+wgPi6SIA1xRE57QJbVYXtH8yTLLTMVRdO3sG2cdZl9IT48t0l3DsULVe9OGFHptQ5djElFi9KHpSSo/vbvOZTrT2LErlwBIQc/aPVLv8zuzQ1Jq4wxiQU7CDbECynEJ6rHRl5DABaMqDlWrsGdRG2jxlukh7I1YWtoCc7OsGqlhn8aLf30mA52uYKTzLwFxbpsDQZ8T7+bLf4Ebo3WfUF5GE9i4R2fzl44lSbxyJI3AEox9EiiQaUQGInmlCxiiwGub6H3FMUKfMwGG5zbbDvSMhBjBz1zdWsPOjGrY7urnSTCbVrs5X5NE3RZ5YiWxLKjUPT3maPXCpNoslp sW4KVZOc 8CPwGtObBJs8qc/SJEzMNIBnRDiZ8ZWTpR8iDVljZn+R65UA8GWWgARUzw3/8NU2N541FmB07/1HWyCR/yjSMV/ePm/b1Pgp+MiaBxhIV6QLywWgbiZIjxDi785QmzI7E785g+t7iYj2ceIkLKwOBGwteNqrU6P6AM2kHlz51WhEyJyvvLZh4L/tQ0j14lHr4P3A39ZQgIAuT7b7l8Bwb8WAyxyX3VDtbRKTlNoh7qq9VVQp5dOTubiAaC5yMXMCQaxJJHwuQjYc0lfAJaNkgACgOp/0np2Wo2+RvrEoeG9CjiBk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.001159, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Dec 22, 2023 at 3:46=E2=80=AFPM Leonardo Bras = 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 > --- > 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/com= pat.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; > + > + return test_ti_thread_flag(thread, TIF_32BIT); > +} > + Does it make sense to use a #ifdef CONFIG_COMPAT clause to group is_compat_thread() and is_compat_flag()? For example, #ifdef CONFIG_COMPAT static inline int is_compat_thread(struct thread_info *thread) { return test_ti_thread_flag(thread, TIF_32BIT); } static inline int is_compat_task(void) { return is_compat_thread(current); } #else static inline int is_compat_thread(struct thread_info *thread) { return 0; = } static inline int is_compat_task(void) { return 0; } #endif > 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 =3D {= }; > #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 >