BPF: replace low-entropy member with macro
PATCH 1/1 BPF: replace low-entropy member with macro
From: zhongjun <[email protected]>
The member orig_idx is a low-entropy once-init invariable data member. It can be replace by a series of macros. Replace this member by macros can save memory and cpu-time.
base-commit: 919e659ed12568b5b8ba6c2ffdd82d8d31fc28af
--- include/linux/bpf_verifier.h | 3 ++- kernel/bpf/verifier.c | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-)
include/linux/bpf_verifier.h +2 -1
@@ -451,11 +451,12 @@ struct bpf_insn_aux_data {u8 alu_state;/* used in combination with alu_limit */ /* below fields are initialized once */ -unsigned int orig_idx;/* original instruction index */ bool prune_point;bool jmp_point; }; +#define ORIG_IDX_BY_OFF (head, off) (off) +#define MAX_USED_MAPS 64/* max number of maps accessed by one eBPF program */ #define MAX_USED_BTFS 64/* max number of BTFs accessed by one BPF program */
kernel/bpf/verifier.c +2 -4
@@ -15428,7 +15428,7 @@ static struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 ofif (PTR_ERR (new_prog) == -ERANGE )verbose (env,"insn %d cannot be patched due to 16-bit range\n" , - env->insn_aux_data[off].orig_idx); +ORIG_IDX_BY_OFF (env->insn_aux_data, off));vfree (new_data);return NULL ; }
@@ -17652,7 +17652,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr)u64 start_time =ktime_get_ns ();struct bpf_verifier_env *env;struct bpf_verifier_log *log; -int i, len, ret = -EINVAL ; +int len, ret = -EINVAL ;bool is_priv;/* no program is valid */
@@ -17673,8 +17673,6 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr) ret = -ENOMEM ;if (!env->insn_aux_data) goto err_free_env; -for (i =0 ; i < len; i++) - env->insn_aux_data[i].orig_idx = i; env->prog = *prog; env->ops = bpf_verifier_ops[env->prog->type]; env->fd_array =make_bpfptr (attr->fd_array, uattr.is_kernel);
Signature · 1 line
2.20.1
kernel test robot
build botkernel test robot noticed the following build errors:
Hi,
kernel test robot noticed the following build errors:
[auto build test ERROR on 919e659ed12568b5b8ba6c2ffdd82d8d31fc28af]
url: https://github.com/intel-lab-lkp/linux/commits/zhongjun-uniontech-com/BPF-replace-low-entropy-member-with-macro/20230407-113614 base: 919e659ed12568b5b8ba6c2ffdd82d8d31fc28af patch link: https://lore.kernel.org/r/20230407033418.2295-1-zhongjun%40uniontech.com patch subject: [PATCH] BPF: replace low-entropy member with macro config: x86_64-randconfig-a002-20230403 (https://download.01.org/0day-ci/archive/20230407/[email protected]/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/f8ee7d5ddcfe866f9b9b4f18dff368764ea854e5
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review zhongjun-uniontech-com/BPF-replace-low-entropy-member-with-macro/20230407-113614 git checkout f8ee7d5ddcfe866f9b9b4f18dff368764ea854e5
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/net/ethernet/netronome/nfp/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> drivers/net/ethernet/netronome/nfp/bpf/verifier.c:814:57: error: no member named 'orig_idx' in 'struct bpf_insn_aux_data'
meta = nfp_bpf_goto_meta(nfp_prog, meta, aux_data[off].orig_idx);
~~~~~~~~~~~~~ ^
drivers/net/ethernet/netronome/nfp/bpf/verifier.c:827:52: error: no member named 'orig_idx' in 'struct bpf_insn_aux_data'
} else if (meta->jmp_dst->n != aux_data[tgt_off].orig_idx) {
~~~~~~~~~~~~~~~~~ ^
drivers/net/ethernet/netronome/nfp/bpf/verifier.c:830:23: error: no member named 'orig_idx' in 'struct bpf_insn_aux_data'
aux_data[tgt_off].orig_idx);
~~~~~~~~~~~~~~~~~ ^
drivers/net/ethernet/netronome/nfp/bpf/verifier.c:17:46: note: expanded from macro 'pr_vlog'
bpf_verifier_log_write(env, "[nfp] " fmt, ##__VA_ARGS__)
^~~~~~~~~~~
drivers/net/ethernet/netronome/nfp/bpf/verifier.c:848:57: error: no member named 'orig_idx' in 'struct bpf_insn_aux_data'
meta = nfp_bpf_goto_meta(nfp_prog, meta, aux_data[off].orig_idx);
~~~~~~~~~~~~~ ^4 errors generated.
vim +814 drivers/net/ethernet/netronome/nfp/bpf/verifier.c
a32014b351662f Jakub Kicinski 2019-01-22 806
a32014b351662f Jakub Kicinski 2019-01-22 807 int nfp_bpf_opt_replace_insn(struct bpf_verifier_env *env, u32 off,
a32014b351662f Jakub Kicinski 2019-01-22 808 struct bpf_insn *insn)
a32014b351662f Jakub Kicinski 2019-01-22 809 {
a32014b351662f Jakub Kicinski 2019-01-22 810 struct nfp_prog *nfp_prog = env->prog->aux->offload->dev_priv;
a32014b351662f Jakub Kicinski 2019-01-22 811 struct bpf_insn_aux_data *aux_data = env->insn_aux_data;
a32014b351662f Jakub Kicinski 2019-01-22 812 struct nfp_insn_meta *meta = nfp_prog->verifier_meta;
a32014b351662f Jakub Kicinski 2019-01-22 813
a32014b351662f Jakub Kicinski 2019-01-22 @814 meta = nfp_bpf_goto_meta(nfp_prog, meta, aux_data[off].orig_idx);
a32014b351662f Jakub Kicinski 2019-01-22 815 nfp_prog->verifier_meta = meta;
a32014b351662f Jakub Kicinski 2019-01-22 816
a32014b351662f Jakub Kicinski 2019-01-22 817 /* conditional jump to jump conversion */
a32014b351662f Jakub Kicinski 2019-01-22 818 if (is_mbpf_cond_jump(meta) &&
a32014b351662f Jakub Kicinski 2019-01-22 819 insn->code == (BPF_JMP | BPF_JA | BPF_K)) {
a32014b351662f Jakub Kicinski 2019-01-22 820 unsigned int tgt_off;
a32014b351662f Jakub Kicinski 2019-01-22 821
a32014b351662f Jakub Kicinski 2019-01-22 822 tgt_off = off + insn->off + 1;
a32014b351662f Jakub Kicinski 2019-01-22 823
a32014b351662f Jakub Kicinski 2019-01-22 824 if (!insn->off) {
a32014b351662f Jakub Kicinski 2019-01-22 825 meta->jmp_dst = list_next_entry(meta, l);
a32014b351662f Jakub Kicinski 2019-01-22 826 meta->jump_neg_op = false;
a32014b351662f Jakub Kicinski 2019-01-22 827 } else if (meta->jmp_dst->n != aux_data[tgt_off].orig_idx) {
a32014b351662f Jakub Kicinski 2019-01-22 828 pr_vlog(env, "branch hard wire at %d changes target %d -> %d\n",
a32014b351662f Jakub Kicinski 2019-01-22 829 off, meta->jmp_dst->n,
a32014b351662f Jakub Kicinski 2019-01-22 830 aux_data[tgt_off].orig_idx);
a32014b351662f Jakub Kicinski 2019-01-22 831 return -EINVAL;
a32014b351662f Jakub Kicinski 2019-01-22 832 }
a32014b351662f Jakub Kicinski 2019-01-22 833 return 0;
a32014b351662f Jakub Kicinski 2019-01-22 834 }
a32014b351662f Jakub Kicinski 2019-01-22 835
a32014b351662f Jakub Kicinski 2019-01-22 836 pr_vlog(env, "unsupported instruction replacement %hhx -> %hhx\n",
a32014b351662f Jakub Kicinski 2019-01-22 837 meta->insn.code, insn->code);
a32014b351662f Jakub Kicinski 2019-01-22 838 return -EINVAL;
a32014b351662f Jakub Kicinski 2019-01-22 839 }
9a06927e778bc4 Jakub Kicinski 2019-01-22 840 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests