BPF List
 help / color / mirror / Atom feed
From: Leon Hwang <leon.hwang@linux.dev>
To: Tiezhu Yang <yangtiezhu@loongson.cn>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	KaFai Wan <kafai.wan@linux.dev>
Cc: bpf@vger.kernel.org, loongarch@lists.linux.dev
Subject: Re: [PATCH bpf-next v5] bpf: Reject programs with inlined helpers if JIT is unavailable
Date: Thu, 2 Jul 2026 11:17:06 +0800	[thread overview]
Message-ID: <3fe115fd-8df8-4bf0-805b-2d0c2c40fdf5@linux.dev> (raw)
In-Reply-To: <20260702022108.17693-1-yangtiezhu@loongson.cn>

On 2/7/26 10:21, Tiezhu Yang wrote:
[...]
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index ba09795e0bfd..463fae6a5c33 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -1865,8 +1865,9 @@ struct bpf_prog_aux {
>  
>  struct bpf_prog {
>  	u16			pages;		/* Number of allocated pages */
> -	u16			jited:1,	/* Is our filter JIT'ed? */
> +	u32			jited:1,	/* Is our filter JIT'ed? */
>  				jit_requested:1,/* archs need to JIT the prog */
> +				jit_required:1, /* program strictly requires JIT compiler */

Looks good to put jit_required together with jit_requested.

However, 'u16 -> u32' changes the layout of struct bpf_prog.

Before the change, pahole -C bpf_prog ./vmlinux

struct bpf_prog {
	u16                        pages;                /*     0     2 */
	u16                        jited:1;              /*     2: 0  2 */
	u16                        jit_requested:1;      /*     2: 1  2 */
	u16                        gpl_compatible:1;     /*     2: 2  2 */
	u16                        cb_access:1;          /*     2: 3  2 */
	u16                        dst_needed:1;         /*     2: 4  2 */
	u16                        blinding_requested:1; /*     2: 5  2 */
	u16                        blinded:1;            /*     2: 6  2 */
	u16                        is_func:1;            /*     2: 7  2 */
	u16                        kprobe_override:1;    /*     2: 8  2 */
	u16                        has_callchain_buf:1;  /*     2: 9  2 */
	u16                        enforce_expected_attach_type:1; /*     2:10
2 */
	u16                        call_get_stack:1;     /*     2:11  2 */
	u16                        call_get_func_ip:1;   /*     2:12  2 */
	u16                        call_session_cookie:1; /*     2:13  2 */
	u16                        tstamp_type_access:1; /*     2:14  2 */
	u16                        sleepable:1;          /*     2:15  2 */
	enum bpf_prog_type         type;                 /*     4     4 */
	enum bpf_attach_type       expected_attach_type; /*     8     4 */
	u32                        len;                  /*    12     4 */
	u32                        jited_len;            /*    16     4 */
	union {
		u8                 digest[32];           /*    20    32 */
		u8                 tag[8];               /*    20     8 */
	};                                               /*    20    32 */

	/* XXX 4 bytes hole, try to pack */

	struct bpf_prog_stats *    stats;                /*    56     8 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	u8 *                       active;               /*    64     8 */
	unsigned int               (*bpf_func)(const void  *, const struct
bpf_insn  *); /*    72     8 */
	struct bpf_prog_aux *      aux;                  /*    80     8 */
	struct sock_fprog_kern *   orig_prog;            /*    88     8 */
	union {
		struct {
			struct {
			} __empty_insns;                 /*    96     0 */
			struct sock_filter insns[0];     /*    96     0 */
		};                                       /*    96     0 */
		struct {
			struct {
			} __empty_insnsi;                /*    96     0 */
			struct bpf_insn insnsi[0];       /*    96     0 */
		};                                       /*    96     0 */
	};                                               /*    96     0 */

	/* size: 96, cachelines: 2, members: 28 */
	/* sum members: 90, holes: 1, sum holes: 4 */
	/* sum bitfield members: 16 bits (2 bytes) */
	/* last cacheline: 32 bytes */
};


After the change, pahole -C bpf_prog ./vmlinux

struct bpf_prog {
	u16                        pages;                /*     0     2 */

	/* Bitfield combined with previous fields */

	u32                        jited:1;              /*     0:16  4 */
	u32                        jit_requested:1;      /*     0:17  4 */
	u32                        jit_required:1;       /*     0:18  4 */
	u32                        gpl_compatible:1;     /*     0:19  4 */
	u32                        cb_access:1;          /*     0:20  4 */
	u32                        dst_needed:1;         /*     0:21  4 */
	u32                        blinding_requested:1; /*     0:22  4 */
	u32                        blinded:1;            /*     0:23  4 */
	u32                        is_func:1;            /*     0:24  4 */
	u32                        kprobe_override:1;    /*     0:25  4 */
	u32                        has_callchain_buf:1;  /*     0:26  4 */
	u32                        enforce_expected_attach_type:1; /*     0:27
4 */
	u32                        call_get_stack:1;     /*     0:28  4 */
	u32                        call_get_func_ip:1;   /*     0:29  4 */
	u32                        call_session_cookie:1; /*     0:30  4 */
	u32                        tstamp_type_access:1; /*     0:31  4 */
	u32                        sleepable:1;          /*     4: 0  4 */

	/* XXX 31 bits hole, try to pack */

	enum bpf_prog_type         type;                 /*     8     4 */
	enum bpf_attach_type       expected_attach_type; /*    12     4 */
	u32                        len;                  /*    16     4 */
	u32                        jited_len;            /*    20     4 */
	union {
		u8                 digest[32];           /*    24    32 */
		u8                 tag[8];               /*    24     8 */
	};                                               /*    24    32 */
	struct bpf_prog_stats *    stats;                /*    56     8 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	u8 *                       active;               /*    64     8 */
	unsigned int               (*bpf_func)(const void  *, const struct
bpf_insn  *); /*    72     8 */
	struct bpf_prog_aux *      aux;                  /*    80     8 */
	struct sock_fprog_kern *   orig_prog;            /*    88     8 */
	union {
		struct {
			struct {
			} __empty_insns;                 /*    96     0 */
			struct sock_filter insns[0];     /*    96     0 */
		};                                       /*    96     0 */
		struct {
			struct {
			} __empty_insnsi;                /*    96     0 */
			struct bpf_insn insnsi[0];       /*    96     0 */
		};                                       /*    96     0 */
	};                                               /*    96     0 */

	/* size: 96, cachelines: 2, members: 29 */
	/* sum members: 90 */
	/* sum bitfield members: 17 bits, bit holes: 1, sum bit holes: 31 bits */
	/* last cacheline: 32 bytes */
};


Luckily, the total size keeps 96 bytes. The layout change is the hole:
from 4 bytes to 31 bits.

Thanks,
Leon

>  				gpl_compatible:1, /* Is filter GPL compatible? */
>  				cb_access:1,	/* Is control block accessed? */
>  				dst_needed:1,	/* Do we need dst entry? */
> [...]

  reply	other threads:[~2026-07-02  3:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-02  2:21 [PATCH bpf-next v5] bpf: Reject programs with inlined helpers if JIT is unavailable Tiezhu Yang
2026-07-02  3:17 ` Leon Hwang [this message]
2026-07-02  3:31   ` Tiezhu Yang
2026-07-02  5:39     ` Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3fe115fd-8df8-4bf0-805b-2d0c2c40fdf5@linux.dev \
    --to=leon.hwang@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=jolsa@kernel.org \
    --cc=kafai.wan@linux.dev \
    --cc=loongarch@lists.linux.dev \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=song@kernel.org \
    --cc=yangtiezhu@loongson.cn \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox