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 29F3DC46CD2 for ; Thu, 28 Dec 2023 03:11:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 152766B0082; Wed, 27 Dec 2023 22:11:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 102116B0083; Wed, 27 Dec 2023 22:11:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0BE66B0085; Wed, 27 Dec 2023 22:11:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E21E56B0082 for ; Wed, 27 Dec 2023 22:11:13 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B111E160737 for ; Thu, 28 Dec 2023 03:11:13 +0000 (UTC) X-FDA: 81614750826.10.AD5D914 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by imf26.hostedemail.com (Postfix) with ESMTP id BE8B4140007 for ; Thu, 28 Dec 2023 03:11:11 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=Hr3ZLmVI; spf=pass (imf26.hostedemail.com: domain of andy.chiu@sifive.com designates 209.85.167.41 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=1703733072; 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=3tojWnjZoOPArkc/1ypwctKQDulVjKNakYJmlzZOcB4=; b=AmHmxC682IRyLfzVcnefavi2cep/xg3civZdM3ueD/JkjfznIQmfbz12VrWISfhpajxFDW 5PYqGzxyxjNtL935wlQjJvufVZdf2PwA6HVqVNj6kx+PpPBRXD9727mdtefZXHdNS4QGGo C1bOhGTDEJ6DoY+oIADLqH67N11rwBQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703733072; a=rsa-sha256; cv=none; b=f+/8YvGmknu/uJI8+72iwxmfmVc3bvXPtQfeKzLyTn8deyc5bFf8sJwsHKkQ2XhBXItSpS BgfK07hjczN6O3GjUgAs1cGwuir5hQDWptryqUVj/Wd7OMwiunc8Drhm4Y/kqr8L+hOzj5 3w5l3Jtgd0VZiBA5TjYKAJeOIyga3mo= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=Hr3ZLmVI; spf=pass (imf26.hostedemail.com: domain of andy.chiu@sifive.com designates 209.85.167.41 as permitted sender) smtp.mailfrom=andy.chiu@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-50e67e37661so5355056e87.0 for ; Wed, 27 Dec 2023 19:11:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1703733070; x=1704337870; 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=3tojWnjZoOPArkc/1ypwctKQDulVjKNakYJmlzZOcB4=; b=Hr3ZLmVIQbYbpRO74kOhEd6WoldHOTbaL4TfMpTVG9Afm/ohH5firzda8Anjw0eQpA duDu4wubTKEmlNhQK05EsrrcgEC5kFjIi9SqN3/uuhvYrJ3xRLQ4/7H3lX5cm7Qa1VG2 EafUj+dfxkudx7M3qCJljhNc7iNzslBiLE1QnItRizy8QLe8wgwdubx1w6DA361KFwPd KL/sAr8F1P/Weurht/8bALA+gfqRD3wXsCWjli2PvzRQBgvKdchDK/YKVqMo/OWOJG4a x9p2QKX0a91zOdBMvKEnoTSiiTHqtvdn5WPsQ7O0HTdJZ9MrE6jCl8nJ9jWW8ZDQh/Zz bK6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703733070; x=1704337870; 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=3tojWnjZoOPArkc/1ypwctKQDulVjKNakYJmlzZOcB4=; b=L0piHhtw2Vn82PFZHGHljl3tM6WV4budtkCVJpVseFnLDka5lp2QdwGFgi802lEtqb joHJ0H0cZUCdbgqQCzo0tCyoPxm2y22LxJKnLUALODjD5pk6FCL8XCtmTEzSDBn6V9tq sQ73+O9MJsKl1IjqELi2pixJiGzrWg/TaB6pdxlTQxYR359SsBQAx95ghHuKxGxJtxBr nwxFo5Y+bmMhg9Qz5L7H/G9rBMGYnROe9r/YZ4ZH3ZvLdhUkUpVrEqGcmNFPGbsGKIhd m4yD8/Sa2eqzUtE2Mv51eCPjmFVQgiFt/MhhC0s43hVaP7M2MbInBuU7Ugc/M2rN+cTj puzA== X-Gm-Message-State: AOJu0YzB43UvH15dHKjJ20NNjCWKH2VPdZ8OE2JjCYJhG2V3pB/YUI8K R8Bnq9J0HvSKMql7kb00o4v5OCg7N4avHaAuVc+W2vs9ixFgQQ== X-Google-Smtp-Source: AGHT+IG9tZ2wg3iQJxAba0ROVCc95Rf84jfl7lOU9lpNNGSZonGS7SyM+Cc8rxSMb7fcGUKgiCL1TrxxQvgJyBtlTKA= X-Received: by 2002:ac2:5504:0:b0:50e:6a21:f9b2 with SMTP id j4-20020ac25504000000b0050e6a21f9b2mr3399360lfk.55.1703733069697; Wed, 27 Dec 2023 19:11:09 -0800 (PST) MIME-Version: 1.0 References: <20231222074605.452452-1-leobras@redhat.com> <20231222074605.452452-4-leobras@redhat.com> In-Reply-To: From: Andy Chiu Date: Thu, 28 Dec 2023 11:10:58 +0800 Message-ID: Subject: Re: [RFC PATCH 3/4] riscv: Introduce is_compat_thread() into compat.h To: Leonardo Bras Soares Passos 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-Queue-Id: BE8B4140007 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: z7ugac19ye4cpzu55sxq91mbmqunriiq X-HE-Tag: 1703733071-438824 X-HE-Meta: U2FsdGVkX1/WDyCZQjTi2hujq3pMvac9FIp/jTwtnJhyDrDJc1ckQoZR49Nhh3hV46dFxwd6RV1TmCmbYmTNidlTnDeZx1ydRdc3Bl2zwxo0Dfl4XB+CG2Xy9cQUOKMkj+LYHXt1FUn/NylLsoW/7MfwA9ColZ/ZeQYLJmrObsxQJH9p6+4KMBit+icvJajWFjqUjZtWx8iP5jzZmOmn2Lszp/TbOXJXwg0Kx36Pk03MrGp6ziC3yHYq1En4jto7zjg/Nf5Ha4dk9FJ4yQI2RwTi86awZV/+ln/FKUfZ4jYWZ2DZSnUIo/crufeYsTCi239tAPql07XICGA+uJUB2QYmtUfI5+p7oM83+c1z8b3NsS4hj80Wu5DhJ+9uTrwcRSt0U2xRK5jVMFVcfH0WdpSfBTUyRNwT8/UUfZZEHmBttltzyKqmQ8nweIqt1D/pqJORV7jys+pbBT6/2UlD48LkiOcO+osLa4Xu2Is0FNlKpoKZnI12h7Y4fG0OMt8AIxh3w+8Ij2m5pG/TItq22NUwilvOtPscaSR287m0CHoqgGz8nfFO48hYDnY4dVzL8SxvqA/fS93apVevpE4ayHNj25vAYig5AOC6HxyoDVhPjVOw5Y2uxtRR4Zui4MP7VRaOQ/wkX2MuZsUisNPt8mX+jhBSymu0nTb924e4s5pnoMdKrtoaa5hHPyTGthfiCGuWqgB41BvQFzDTELWQBVX6r1SDJ4v6UM8lsNxljxCwTH7l5MWcEACByO9qdcPOIr1z2WHDTSejkBQJkWHrCvfRwNL7LQK3Lbgo/+dnIeQ1ErxeGeFc9iKWCwID3Rd0CG9lz0Mh27Bk3VpKUaAw3HueT6Bj02jE/xORkkfpvbteE5u0LQnwN0iZJRoc1gMhogORuuPio9fPIIICp/CIk1foEQ+oJzDDMfsgRiRwxxcOwkYjdhTtb6D6N4VXl7MVRdyvJn0+fw9TMFQrAe3 uUXT2iq7 Y1YwOHubc6vjhLnfLfjy2ED2MwaKbHDWI6eBlaT/5ts8gTFMzhD4DTgnzh24bNcwfUFu0pGHTcDrCWJ/vcvTNAbdITOCspZF8PcBkq8JWHO9nG8BROnaHjJ9XxlPzaL1wFIBoAMckRukeRGrmbn/edEeJMXN2S7yyzT6e4HLAtqeJv0mrN9WlK5bC/j3Dv9R1F7wlo04uffknJGb2k0p0SmZOw/VDFJG4RwEZdfkVqxoKvUsW2Al88U2fF7vKH/UZmbpQU2UI5nBlvg70UwiOd3oz4SHxXxn06cGq671yLdA7cz5SDsAukvoODWpRfi4Gj0SRrGb3EU/0YsUnav0uOdua+DjMZGqc+J8+ X-Bogosity: Ham, tests=bogofilter, spamicity=0.012091, 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 Wed, Dec 27, 2023 at 3:25=E2=80=AFAM Leonardo Bras Soares Passos wrote: > > On Sat, Dec 23, 2023 at 1:26=E2=80=AFAM Andy Chiu = wrote: > > > > 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 th= e > > > 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= /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; > > > + > > > + 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, > > Hello Andy, > > Sure, it does make sense. > > But I honestly think that using IS_ENABLED() instead of #ifdef + > multiple same-named functions works better for code reading, at least > for small functions such as these. > > Does this make sense? > > Thanks for reviewing! > Leo Hi, yes! It makes sense to me. Reviewed-by: Andy Chiu Thanks, Andy > > > > > > #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 *chi= ld, 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_str= uct *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 > > > > > >