Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1209109rdb; Fri, 22 Dec 2023 20:26:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IELyaMkT1YQDWiQhwNvfy+VtMJAFEiH8GiaCZeyzssyaEDlgdLykFwHrZBkW7K1Vm/P2J4m X-Received: by 2002:a17:906:2807:b0:a26:9876:ae88 with SMTP id r7-20020a170906280700b00a269876ae88mr888764ejc.73.1703305568735; Fri, 22 Dec 2023 20:26:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703305568; cv=none; d=google.com; s=arc-20160816; b=HZicqPI8OtiUsKOotgrPiXDz+/ITV9rABhKP3O+qU/+1V8tCXDzMEwLisTHU1LiuCJ dI3r5qCg1FedK9eUbivcWYh/d6ahf3p2xIHK7SaQ1NvKZNGZwPv0XdVavWDy+UPQMXeE SXRsrvQF9L9oc8MF+RDtap9D8X/owVAXQKqmRQVhmNmweqQlVt885sSBctI7zXw9mX4/ PLTp6FUkhw04tWenShlhqnTfwB1XhKCBSNpXW3zUowOn5Z4pi4wSCQWGZ5q7LiyZygBe HOK2gF5FKWzJtffgw5XwDiJBG6iMgxPSANmPTka96VHmPZvTBvErjhF0kKki5WK5KnyO vNfA== 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=Oh1r+51kM+XQXoePZoBYVvIPaqSuNTim190BEuHTp1w=; fh=g+8I1xlaVf9t/4gBMOHOkHToO3pSHxaXaSZPwcy5DEc=; b=jj+3EsJ5Q/Y1HlzSwve34RS6xP4Zsz2C24EZG+JFyRJmKza73zY88s3hL+Jawk24J5 /i6wkz0zHcVmlrn7pkEacN4Hs+K5PTJbUx3F4FUN6GooFqX0TCyeK6R23nZCzkQS5JpQ k5/jt4hAxwMwnUVLRsa6rMB5d8B0almYzA/dIjT1AhlGKOYzwD1NUWksM1aDPnMgquFv zDDBSbRmeVJb1bPvzJtuEv9W/TvCgxyjFFoaoXq4ocOqzIgJXWOWJQo+Rj6wSXQB+h2K +FdsHptUmH2L8GsKtYcBeaJInzRSkPRscYBtalZebYyOwzGUkGjmf3kglVCmgh+L+W0u 4DVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=LOlNAYby; spf=pass (google.com: domain of linux-kernel+bounces-10285-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10285-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id lf25-20020a170906ae5900b00a2330958787si2395918ejb.757.2023.12.22.20.26.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 20:26:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10285-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=LOlNAYby; spf=pass (google.com: domain of linux-kernel+bounces-10285-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10285-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 433971F22F14 for ; Sat, 23 Dec 2023 04:26:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1EFE6110; Sat, 23 Dec 2023 04:26:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="LOlNAYby" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (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 484624C69 for ; Sat, 23 Dec 2023 04:25:58 +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-f46.google.com with SMTP id 2adb3069b0e04-50e72e3d435so301450e87.2 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=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=Oh1r+51kM+XQXoePZoBYVvIPaqSuNTim190BEuHTp1w=; b=LOlNAYbyftVc9hewL9cw2dzj39ChYUye/cjog9IW1UyX/BVz+Rl82WAy29CD0lJN6V dbBN5eTniK+iKgonvsjo5aCy6fh52qB/39zlpHPxOmaD1IhtiKGFYSdPdlPPYwaYSo+E WgEaXrFUCD88q5RC5Kp8xpbBc6FHYpfNiCqpZRetQ6MW3JvTyvVBOek3MhK0AJeQ84g1 jQNi7QNqCp2HWd9mGLsitZ0dPBpZANyZaESKNNMq1jRwbG1Gx/0Mkv6vjrSZaLUIWA9c 6YrXxVISVYpjAzUMslCU/yFDguBM43crcHXPssD9rjXPTbj8QWaQC56D7bXEm8L4+2Tm 1DLw== 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=mcPH4SsaNLcu1t0/IUG4zNmmriL0MnF2Ocex62nXHnFEgETmCR7MsLO4Df4B7ET+GW dUNrXZ0trzDpLwc0deOfhuuxLFnLMgyrqGMnxipky8/pLZ1dExjkJeAG1xl5w5sgnjlv MLu4KtqWdB8zgGPI13IX507hULUqAE+xD0ZUXk+mJGDGZoBpQ6MPqzbx8K2lVixgMdB0 IItzTx7ma5bkH/24g4ZO06cNxGvZKShJc9Uu+Vvl3JmLsl8gD9p2oU65tvwPZKxGRhcg TnkYjL+sMnPraR0jdoIU63Npm2h9g+KWGzVyhAV96d7ExgZftvouO7WKJDwV+V2LXEum 185w== X-Gm-Message-State: AOJu0YxQ1KjNhBEgso+1MuT/qJ7tnRhVm6FqmUwke9/SYafgihHp3Kjb 0xl1ToRL3NdBeT3rW2uAeYyXjjKKEa2OjSsW+z5c34bvKw94Vg== 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) 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: 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 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 >