diff mbox series

BPF: replace low-entropy member with macro

Message ID 20230407033418.2295-1-zhongjun@uniontech.com (mailing list archive)
State Rejected
Delegated to: BPF
Headers show
Series BPF: replace low-entropy member with macro | expand

Checks

Context Check Description
bpf/vmtest-bpf-PR success PR summary
bpf/vmtest-bpf-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-VM_Test-3 success Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-5 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-VM_Test-6 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-7 success Logs for set-matrix
bpf/vmtest-bpf-VM_Test-4 success Logs for build for s390x with gcc
bpf/vmtest-bpf-VM_Test-8 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-9 success Logs for test_maps on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-11 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-12 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-13 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-14 success Logs for test_progs on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-16 fail Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-17 fail Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-18 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-19 success Logs for test_progs_no_alu32 on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-21 fail Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-22 fail Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-23 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-24 success Logs for test_progs_no_alu32_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-25 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-26 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-27 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-28 success Logs for test_progs_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-29 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-30 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-31 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-32 success Logs for test_verifier on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-33 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-VM_Test-34 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-35 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-15 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-VM_Test-20 success Logs for test_progs_no_alu32 on s390x with gcc
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 86 this patch: 96
netdev/cc_maintainers fail 11 maintainers not CCed: andrii@kernel.org song@kernel.org sdf@google.com haoluo@google.com yhs@fb.com daniel@iogearbox.net john.fastabend@gmail.com kpsingh@kernel.org jolsa@kernel.org martin.lau@linux.dev ast@kernel.org
netdev/build_clang fail Errors and warnings before: 30 this patch: 43
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 86 this patch: 96
netdev/checkpatch warning WARNING: From:/Signed-off-by: email name mismatch: 'From: zhongjun <zhongjun@uniontech.com>' != 'Signed-off-by: Jun Zhong <zhongjun@uniontech.com>'
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-VM_Test-10 success Logs for test_maps on s390x with gcc

Commit Message

zhongjun@uniontech.com April 7, 2023, 3:34 a.m. UTC
From: zhongjun <zhongjun@uniontech.com>

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.

Signed-off-by: Jun Zhong <zhongjun@uniontech.com>
base-commit: 919e659ed12568b5b8ba6c2ffdd82d8d31fc28af
---
 include/linux/bpf_verifier.h | 3 ++-
 kernel/bpf/verifier.c        | 6 ++----
 2 files changed, 4 insertions(+), 5 deletions(-)

Comments

kernel test robot April 7, 2023, 11:28 a.m. UTC | #1
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/202304071944.aYRCuc4u-lkp@intel.com/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 <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202304071944.aYRCuc4u-lkp@intel.com/

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
diff mbox series

Patch

diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index cf1bb1cf4a7b..8783d90a21bb 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -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 */
 
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index d517d13878cf..e2545cd128d8 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -15428,7 +15428,7 @@  static struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 of
 		if (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);