Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp727730rdb; Fri, 22 Dec 2023 03:20:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFa557CwxOC18m1BamOlsX1jOYtb7RllWH71VVx2AFkwrRpMQjv54x7nCDyTgBPOEgXwAeD X-Received: by 2002:a17:902:e5c6:b0:1d1:cdd8:61ae with SMTP id u6-20020a170902e5c600b001d1cdd861aemr934117plf.102.1703244056320; Fri, 22 Dec 2023 03:20:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703244056; cv=none; d=google.com; s=arc-20160816; b=i786tKa/vz32DDSN0gZF5lITFz4+2ahy3Wb/OsFMeq0/57360it2LjKjeTxlW1kLA6 GY3o4JfOSc8cVVzNL0asmW3+EG7fakv4p22Z1TmsQrcrzGmRTmZ3tn7AMdJB0K+5Ozgt +W/mEIWZYNBOCHrOfBb5X0d7pDfvrUySmuQh0UrjXBgUjb9cNjUWfaq1I9xnf+lXZsg/ ImLCOQslgEJVCWGjylnwZZjitzis+L/+6D9fdlAOGlDXFcTmGnq8evBPiqjlWS+GNUpM dnfjhW1+TXbzBDDk9z0f9rBzOi8CD9Rxkf06HPG/6RVF9v9VGaIRfRfP/FiugBOALlM1 pDJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=ThXr9sq+YTt+D9kbPpfTWx0VWdIcB9LkZ/oyitqdPlA=; fh=MSDPJIgNA+oz9s0OIIy1OGBF8jcy0QBjD/wwDTyyqyQ=; b=PDNleQtZZ3BEmYPM5J+qeP1sPulnd/3c/PZx1l2c/b8UpSph8XYJNcHsEJJxNskkk1 aqAuL5wDqcM+xqnDWx0LZ/STDBqoH9Q5CCxhrQQhKZTq9HpLVgbmsbZfK9T3XhUdbe2j +2m22FA/PSMkK2DwyI5LxeYnCn3XGVIXuh+RH7SjnwkJjjwK3J//LA01C2PRo8eUthyC dguoQsu9GKyc+5FTGYTxiAdpXDXCUhEctS4NKc7BSoBzghnN+rQ2QCpSMf/S710ReAWw 4mbon4SIpkDyM+D2oVeLtmFooFDjXxSWo0d9S/6bXxHqp7DdpaMb67nkBYQQGDlAUB3I 6oPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="B/uUWFPk"; spf=pass (google.com: domain of linux-kernel+bounces-9656-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9656-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id a3-20020a170902ecc300b001c383a64ebesi3095862plh.319.2023.12.22.03.20.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 03:20:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9656-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="B/uUWFPk"; spf=pass (google.com: domain of linux-kernel+bounces-9656-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9656-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 01A29281B93 for ; Fri, 22 Dec 2023 11:20:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A35B8171C5; Fri, 22 Dec 2023 11:20:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="B/uUWFPk" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD27B168A2 for ; Fri, 22 Dec 2023 11:20:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DBDDC433AD for ; Fri, 22 Dec 2023 11:20:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703244049; bh=VyOf0Nbm3eElcobcOdq0RIskLo4Ccvqk/gGgSWsd0Ec=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=B/uUWFPkoXZAriI8VSvKQWlcAu38i2HNMHne6Q7pWbHNRtVu9hAkTWoomJtHF40gN gkVKQGd84Ri994M8KJ3F58/CeFBkV2fxc8cS5KtX/dfVIFfvvPjWnfuRF3DYlFWIzb 3N7vgTiziO63zUTPlw9x2s3dNxPeKGPZRquRva77oA4X9UyXqjg+bEOWKEjEuKOT88 9H2vhUsSpuzdHjikz3ehvq9ltcCxulVphnYmjowwbQJqtfiCRAg5NPSjl91rZk+IQC FsPX9IIlW7l0ifXpmG4wFP8tulZShu71fuJHBe5V4mipxu1zYrYdAzD7D4a/NpzA44 86Bnw/AwHZ+gQ== Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a235e394758so193557366b.1 for ; Fri, 22 Dec 2023 03:20:49 -0800 (PST) X-Gm-Message-State: AOJu0Yy9Nn2KSLDZEUfkfYdqna4DnMbYfeMdbwwkDQVg2uuc8K2/zVfD jLMuGlDSqJohujbvr7mKeN7l+fclF8fYA4awZmg= X-Received: by 2002:a17:906:51cf:b0:a19:a19b:78cf with SMTP id v15-20020a17090651cf00b00a19a19b78cfmr695212ejk.146.1703244047649; Fri, 22 Dec 2023 03:20:47 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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: Guo Ren Date: Fri, 22 Dec 2023 19:20:36 +0800 X-Gmail-Original-Message-ID: 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 , Andy Chiu , 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?= , 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 On Fri, Dec 22, 2023 at 3:47=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; 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 =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 > LGTM Reviewed-by: Guo Ren --=20 Best Regards Guo Ren