bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpf: Replace (arg_type & MEM_RDONLY) with type_is_rdonly_mem
@ 2025-01-07  9:02 Feng Yang
  2025-01-07 23:02 ` Stanislav Fomichev
  0 siblings, 1 reply; 4+ messages in thread
From: Feng Yang @ 2025-01-07  9:02 UTC (permalink / raw)
  To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
	yonghong.song, kpsingh, sdf, haoluo, jolsa
  Cc: bpf, linux-kernel

From: Feng Yang <yangfeng@kylinos.cn>

The existing 'type_is_rdonly_mem' function is more formal in linux source

Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
---
 kernel/bpf/verifier.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index d8520095ca03..d1b6b587a146 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -7779,7 +7779,7 @@ static int process_dynptr_func(struct bpf_verifier_env *env, int regno, int insn
 		err = mark_stack_slots_dynptr(env, reg, arg_type, insn_idx, clone_ref_obj_id);
 	} else /* MEM_RDONLY and None case from above */ {
 		/* For the reg->type == PTR_TO_STACK case, bpf_dynptr is never const */
-		if (reg->type == CONST_PTR_TO_DYNPTR && !(arg_type & MEM_RDONLY)) {
+		if (reg->type == CONST_PTR_TO_DYNPTR && !type_is_rdonly_mem(arg_type)) {
 			verbose(env, "cannot pass pointer to const bpf_dynptr, the helper mutates it\n");
 			return -EINVAL;
 		}
@@ -8324,7 +8324,7 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno,
 	 *
 	 * Therefore we fold these flags depending on the arg_type before comparison.
 	 */
-	if (arg_type & MEM_RDONLY)
+	if (type_is_rdonly_mem(arg_type))
 		type &= ~MEM_RDONLY;
 	if (arg_type & PTR_MAYBE_NULL)
 		type &= ~PTR_MAYBE_NULL;
@@ -8356,7 +8356,7 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno,
 		return 0;
 
 	if (compatible == &mem_types) {
-		if (!(arg_type & MEM_RDONLY)) {
+		if (!type_is_rdonly_mem(arg_type)) {
 			verbose(env,
 				"%s() may write into memory pointed by R%d type=%s\n",
 				func_id_name(meta->func_id),
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] bpf: Replace (arg_type & MEM_RDONLY) with type_is_rdonly_mem
  2025-01-07  9:02 [PATCH] bpf: Replace (arg_type & MEM_RDONLY) with type_is_rdonly_mem Feng Yang
@ 2025-01-07 23:02 ` Stanislav Fomichev
  2025-01-08 17:53   ` Alexei Starovoitov
  0 siblings, 1 reply; 4+ messages in thread
From: Stanislav Fomichev @ 2025-01-07 23:02 UTC (permalink / raw)
  To: Feng Yang
  Cc: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
	yonghong.song, kpsingh, sdf, haoluo, jolsa, bpf, linux-kernel

On 01/07, Feng Yang wrote:
> From: Feng Yang <yangfeng@kylinos.cn>
> 
> The existing 'type_is_rdonly_mem' function is more formal in linux source
> 
> Signed-off-by: Feng Yang <yangfeng@kylinos.cn>

Looks ok, but I'm not sure this cleanup is worth it on its own..

Acked-by: Stanislav Fomichev <sdf@fomichev.me>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] bpf: Replace (arg_type & MEM_RDONLY) with type_is_rdonly_mem
  2025-01-07 23:02 ` Stanislav Fomichev
@ 2025-01-08 17:53   ` Alexei Starovoitov
  2025-01-09  8:23     ` Feng Yang
  0 siblings, 1 reply; 4+ messages in thread
From: Alexei Starovoitov @ 2025-01-08 17:53 UTC (permalink / raw)
  To: Stanislav Fomichev
  Cc: Feng Yang, Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Martin KaFai Lau, Eddy Z, Song Liu,
	Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	bpf, LKML

On Tue, Jan 7, 2025 at 3:02 PM Stanislav Fomichev <stfomichev@gmail.com> wrote:
>
> On 01/07, Feng Yang wrote:
> > From: Feng Yang <yangfeng@kylinos.cn>
> >
> > The existing 'type_is_rdonly_mem' function is more formal in linux source
> >
> > Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
>
> Looks ok, but I'm not sure this cleanup is worth it on its own..
>
> Acked-by: Stanislav Fomichev <sdf@fomichev.me>

Yeah.
If we do this let's change type_is_rdonly_mem(u32 type)
to enum as well.

pw-bot: cr

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] bpf: Replace (arg_type & MEM_RDONLY) with type_is_rdonly_mem
  2025-01-08 17:53   ` Alexei Starovoitov
@ 2025-01-09  8:23     ` Feng Yang
  0 siblings, 0 replies; 4+ messages in thread
From: Feng Yang @ 2025-01-09  8:23 UTC (permalink / raw)
  To: alexei.starovoitov
  Cc: andrii, ast, bpf, daniel, eddyz87, haoluo, john.fastabend, jolsa,
	kpsingh, linux-kernel, martin.lau, sdf, song, stfomichev,
	yangfeng59949, yonghong.song

> Yeah.
> If we do this let's change type_is_rdonly_mem(u32 type)
> to enum as well.

> pw-bot: cr

It needs to receive bpf_reg_type and bpf_arg_type, and base_type(u32 type) is also u32.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-01-09  8:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-07  9:02 [PATCH] bpf: Replace (arg_type & MEM_RDONLY) with type_is_rdonly_mem Feng Yang
2025-01-07 23:02 ` Stanislav Fomichev
2025-01-08 17:53   ` Alexei Starovoitov
2025-01-09  8:23     ` Feng Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).