Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3728937rdb; Wed, 27 Dec 2023 19:18:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+wK8ECPs09aMHDEjKWhA2edBDJCnRhMGVAGqdsQYzDLFunXNEjq1fy/wyDXLy6IWvxVfC X-Received: by 2002:a62:84d7:0:b0:6d9:abdb:9018 with SMTP id k206-20020a6284d7000000b006d9abdb9018mr1865476pfd.15.1703733482257; Wed, 27 Dec 2023 19:18:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703733482; cv=none; d=google.com; s=arc-20160816; b=mBJPvV8OeLIbNjmQ/WsNnOv/vAIQWGtDGmPAyxGs4oYO1lhOOi1jPG2qDy3fTCMt8w KVJsn2JihP7onzsJRVKn+WKj7lAVhdKJimGSd15q84zB+XD+u4EDoURgGFtBy/u3qYGu tJ9pCS0fIQkPnbTvvgUORb0gPiOpXsiUvm06XrflLOGxsispxcLaNNC9lmrTqxhyzA4y lLZU7PN+n7Za3N8Bqgk5GVanAdvFHUmWTQUSc4DTb0XP/EQ4o766IeleT4pjuPBXFEM6 828Ztubm7cLaJCMjKzVKKE3E//RxGJepKQZK1UjqXptjbcCi7PTopdwa7CnJYy8wppDW p7wA== 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=3tojWnjZoOPArkc/1ypwctKQDulVjKNakYJmlzZOcB4=; fh=jg2cMe/lPfujzn2I5vRlxjRCCHJRvTys5mNEOypPAbw=; b=q4rDwljIuFPDsvKFwPiyvazg8QlgX5BqEFm/wXf18U3L7awRltA7XB/LNcY7cJiEmu 8eAWgPwf9c2OurJ2eMr2bdzznOI01LffLv57oy9wQm+Gtf637bEzlMR4jF9EByCA+RTl 5frzkkM6Ojmtpx+TUfrgFQY5aVck2EPtc+f/4mIILrKFd2G1VUM4fSec7yca+SR77b64 DsDYMsFwfZ9Ex2rmZ7LlsxmvnQkP7StJHdQwDgZwEU5NTyiWetkUiZ+/7AUiMacU6D9E X6vWjD/3M9WG7l8emKUxazBd3W4UG2w7WLTF3WjB08MFL53QjJZnUmy/s1vtra0KDVVb wc2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=jHDaDhd0; spf=pass (google.com: domain of linux-kernel+bounces-12401-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12401-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id r135-20020a632b8d000000b005c6b4e190b0si9303191pgr.530.2023.12.27.19.18.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 19:18:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12401-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=jHDaDhd0; spf=pass (google.com: domain of linux-kernel+bounces-12401-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12401-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id EB010B22979 for ; Thu, 28 Dec 2023 03:11:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 75D1F137B; Thu, 28 Dec 2023 03:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="jHDaDhd0" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3E3410E5 for ; Thu, 28 Dec 2023 03:11:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-50e81761e43so2277746e87.2 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=vger.kernel.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=jHDaDhd0BO4rf2yQXT8g07bMIxpfwvF0DJbfu+/Oafz3odBqKd5LdhZgXzdXyIBch5 o8K/PGJysWVttf0cz/kcRdh0EQBvrdI8rxUSrw8FRLfkN2FETZqrxgjSNNjtaQkodlKE DIqaq5kZmW8ulCAHgnOlh/eLVRgYDHc9FQgCOmcE6IR/AeujxE8M+QGL9AJBrE5yWi+s RBcQKNk6QUSRCsWze7Y1svVIF4rZNgiT0KGreHtd686o+9PGubC21n03zvecT7De68Q8 g30j5oOyzG87MP79+Z/2HElOGoOHHt4QmxTohX46XPdkCMHiIPYXlE6JiUSuvmTyjqsz IxPw== 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=EH4P9bON8SY9JyU00ShYvjy7C+i9jbwiGyRh1A/8uZy2h87eeLER2d34Z/yIKm8TIq a2c2VIGQcPHyn2B2wWd+6dYvtzT8uZv9sRJDgVtNZr+kCKULPGnc2Ixu+aZgF8f7TZxY cfimVGXN8LGdRc7CwR6sNv1w1EFJ2BFP8qhrRWgBuiOpVX1rYP6gDiSS07hxrZ2zSwVK FD7XoiHau9LAm3k2TRgwo4owv6Pktnf6z0V3yrMfHLFhuPC+vRBe8ktAMgw2V7Va4YXl lHP8yV0GO/vYhluNa5UITdQICrFdTlDNI+RxXhDCPiIzE0hV55h+BPk80Tv18hzxLrtK jzgw== X-Gm-Message-State: AOJu0YzCeDnX+b/bfLD4Me1QJ+V1LZboTc2js6SuC3P3L/itb/yWOVmL pT6dENt2aeGNX9jWQOlk5EOlQqU2tG8TpxDyMjZqlZLnjoMyIQ== 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) 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: 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 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 > > > > > >