CC: [email protected]
CC: [email protected]
CC: [email protected]
TO: Alexei Starovoitov <[email protected]>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/ast/bpf.git relo_core
head:   f17ef55e5e0bac0d11d3186cd1c468b5a1e047d7
commit: 03c354f8c71c2478c421d5552d284e0befb03861 [9/19] bpf: Prepare 
relo_core.c for kernel duty.
:::::: branch date: 20 hours ago
:::::: commit date: 3 days ago
config: arm-randconfig-c002-20211114 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 
c3dddeeafb529e769cde87bd29ef6271ac6bfa5c)
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
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # 
https://git.kernel.org/pub/scm/linux/kernel/git/ast/bpf.git/commit/?id=03c354f8c71c2478c421d5552d284e0befb03861
        git remote add ast-bpf 
https://git.kernel.org/pub/scm/linux/kernel/git/ast/bpf.git
        git fetch --no-tags ast-bpf relo_core
        git checkout 03c354f8c71c2478c421d5552d284e0befb03861
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm 
clang-analyzer 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>


clang-analyzer warnings: (new ones prefixed by >>)
           ^
   include/linux/compiler_types.h:305:2: note: expanded from macro 
'_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:297:3: note: expanded from macro 
'__compiletime_assert'
                   if (!(condition))                                       \
                   ^
   drivers/media/cec/core/cec-api.c:677:4: note: Loop condition is false.  
Exiting loop
                           list_first_entry(&fh->msgs, struct cec_msg_entry, 
list);
                           ^
   include/linux/list.h:522:2: note: expanded from macro 'list_first_entry'
           list_entry((ptr)->next, type, member)
           ^
   include/linux/list.h:511:2: note: expanded from macro 'list_entry'
           container_of(ptr, type, member)
           ^
   include/linux/kernel.h:494:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to 
see all)
   include/linux/compiler_types.h:317:2: note: expanded from macro 
'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, 
__COUNTER__)
           ^
   include/linux/compiler_types.h:305:2: note: expanded from macro 
'_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:295:2: note: expanded from macro 
'__compiletime_assert'
           do {                                                            \
           ^
   drivers/media/cec/core/cec-api.c:680:3: note: Memory is released
                   kfree(entry);
                   ^~~~~~~~~~~~
   drivers/media/cec/core/cec-api.c:675:2: note: Loop condition is true.  
Entering loop body
           while (!list_empty(&fh->msgs)) {
           ^
   drivers/media/cec/core/cec-api.c:677:4: note: Left side of '&&' is false
                           list_first_entry(&fh->msgs, struct cec_msg_entry, 
list);
                           ^
   include/linux/list.h:522:2: note: expanded from macro 'list_first_entry'
           list_entry((ptr)->next, type, member)
           ^
   include/linux/list.h:511:2: note: expanded from macro 'list_entry'
           container_of(ptr, type, member)
           ^
   include/linux/kernel.h:494:61: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
                                                                      ^
   drivers/media/cec/core/cec-api.c:677:4: note: Taking false branch
                           list_first_entry(&fh->msgs, struct cec_msg_entry, 
list);
                           ^
   include/linux/list.h:522:2: note: expanded from macro 'list_first_entry'
           list_entry((ptr)->next, type, member)
           ^
   include/linux/list.h:511:2: note: expanded from macro 'list_entry'
           container_of(ptr, type, member)
           ^
   include/linux/kernel.h:494:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to 
see all)
   include/linux/compiler_types.h:317:2: note: expanded from macro 
'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, 
__COUNTER__)
           ^
   include/linux/compiler_types.h:305:2: note: expanded from macro 
'_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:297:3: note: expanded from macro 
'__compiletime_assert'
                   if (!(condition))                                       \
                   ^
   drivers/media/cec/core/cec-api.c:677:4: note: Loop condition is false.  
Exiting loop
                           list_first_entry(&fh->msgs, struct cec_msg_entry, 
list);
                           ^
   include/linux/list.h:522:2: note: expanded from macro 'list_first_entry'
           list_entry((ptr)->next, type, member)
           ^
   include/linux/list.h:511:2: note: expanded from macro 'list_entry'
           container_of(ptr, type, member)
           ^
   include/linux/kernel.h:494:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to 
see all)
   include/linux/compiler_types.h:317:2: note: expanded from macro 
'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, 
__COUNTER__)
           ^
   include/linux/compiler_types.h:305:2: note: expanded from macro 
'_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:295:2: note: expanded from macro 
'__compiletime_assert'
           do {                                                            \
           ^
   drivers/media/cec/core/cec-api.c:679:3: note: Calling 'list_del'
                   list_del(&entry->list);
                   ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/list.h:147:14: note: Use of memory after it is freed
           entry->next = LIST_POISON1;
           ~~~~~~~~~~~ ^
   Suppressed 1 warnings (1 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use 
-system-headers to display errors from system headers as well.
   1 warning generated.
>> tools/lib/bpf/relo_core.c:1025:7: warning: Branch condition evaluates to a 
>> garbage value [clang-analyzer-core.uninitialized.Branch]
                   if (res->fail_memsz_adjust) {
                       ^
   tools/lib/bpf/relo_core.c:1215:6: note: Assuming 'local_type' is non-null
           if (!local_type)
               ^~~~~~~~~~~
   tools/lib/bpf/relo_core.c:1215:2: note: Taking false branch
           if (!local_type)
           ^
   tools/lib/bpf/relo_core.c:1219:6: note: Assuming 'local_name' is non-null
           if (!local_name)
               ^~~~~~~~~~~
   tools/lib/bpf/relo_core.c:1219:2: note: Taking false branch
           if (!local_name)
           ^
   tools/lib/bpf/relo_core.c:1223:6: note: Calling 'str_is_empty'
           if (str_is_empty(spec_str))
               ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/btf.h:149:9: note: Assuming 's' is non-null
           return !s || !s[0];
                  ^~
   include/linux/btf.h:149:9: note: Left side of '||' is false
   include/linux/btf.h:149:15: note: Assuming the condition is false
           return !s || !s[0];
                        ^~~~~
   include/linux/btf.h:149:2: note: Returning zero, which participates in a 
condition later
           return !s || !s[0];
           ^~~~~~~~~~~~~~~~~~
   tools/lib/bpf/relo_core.c:1223:6: note: Returning from 'str_is_empty'
           if (str_is_empty(spec_str))
               ^~~~~~~~~~~~~~~~~~~~~~
   tools/lib/bpf/relo_core.c:1223:2: note: Taking false branch
           if (str_is_empty(spec_str))
           ^
   tools/lib/bpf/relo_core.c:1227:6: note: Assuming 'err' is 0
           if (err) {
               ^~~
   tools/lib/bpf/relo_core.c:1227:2: note: Taking false branch
           if (err) {
           ^
   tools/lib/bpf/relo_core.c:1241:12: note: Field 'kind' is equal to 
BPF_TYPE_ID_LOCAL
           if (relo->kind == BPF_TYPE_ID_LOCAL) {
                     ^
   tools/lib/bpf/relo_core.c:1241:2: note: Taking true branch
           if (relo->kind == BPF_TYPE_ID_LOCAL) {
           ^
   tools/lib/bpf/relo_core.c:1246:3: note: Control jumps to line 1340
                   goto patch_insn;
                   ^
   tools/lib/bpf/relo_core.c:1340:8: note: Calling 'bpf_core_patch_insn'
           err = bpf_core_patch_insn(prog_name, insn, insn_idx, relo, relo_idx, 
&targ_res);
                 
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   tools/lib/bpf/relo_core.c:981:11: note: Field 'poison' is false
           if (res->poison) {
                    ^
   tools/lib/bpf/relo_core.c:981:2: note: Taking false branch
           if (res->poison) {
           ^
   tools/lib/bpf/relo_core.c:995:2: note: Control jumps to 'case 3:'  at line 
1014
           switch (class) {
           ^
   tools/lib/bpf/relo_core.c:1015:12: note: Field 'validate' is true
                   if (res->validate && insn->off != orig_val) {
                            ^
   tools/lib/bpf/relo_core.c:1015:7: note: Left side of '&&' is true
                   if (res->validate && insn->off != orig_val) {
                       ^
   tools/lib/bpf/relo_core.c:1015:24: note: Assuming 'orig_val' is equal to 
field 'off'
                   if (res->validate && insn->off != orig_val) {
                                        ^~~~~~~~~~~~~~~~~~~~~
   tools/lib/bpf/relo_core.c:1015:3: note: Taking false branch
                   if (res->validate && insn->off != orig_val) {
                   ^
   tools/lib/bpf/relo_core.c:1020:7: note: Assuming the condition is false
                   if (new_val > SHRT_MAX) {
                       ^~~~~~~~~~~~~~~~~~
   tools/lib/bpf/relo_core.c:1020:3: note: Taking false branch
                   if (new_val > SHRT_MAX) {
                   ^
   tools/lib/bpf/relo_core.c:1025:7: note: Branch condition evaluates to a 
garbage value
                   if (res->fail_memsz_adjust) {
                       ^~~~~~~~~~~~~~~~~~~~~~
   1 warning generated.
   drivers/virtio/virtio_balloon.c:266:2: warning: Assigned value is garbage or 
undefined [clang-analyzer-core.uninitialized.Assign]
           list_for_each_entry_safe(page, next, pages, lru) {
           ^
   include/linux/list.h:716:7: note: expanded from macro 
'list_for_each_entry_safe'
                   n = list_next_entry(pos, member);                       \
                       ^
   include/linux/list.h:555:2: note: expanded from macro 'list_next_entry'
           list_entry((pos)->member.next, typeof(*(pos)), member)
           ^
   include/linux/list.h:511:2: note: expanded from macro 'list_entry'
           container_of(ptr, type, member)
           ^
   include/linux/kernel.h:493:2: note: expanded from macro 'container_of'
           void *__mptr = (void *)(ptr);                                   \
           ^
   drivers/virtio/virtio_balloon.c:1104:2: note: Calling 'remove_common'
           remove_common(vb);
           ^~~~~~~~~~~~~~~~~

vim +1025 tools/lib/bpf/relo_core.c

b0588390dbcedc Alexei Starovoitov 2021-07-20   954  
b0588390dbcedc Alexei Starovoitov 2021-07-20   955  /*
b0588390dbcedc Alexei Starovoitov 2021-07-20   956   * Patch relocatable BPF 
instruction.
b0588390dbcedc Alexei Starovoitov 2021-07-20   957   *
b0588390dbcedc Alexei Starovoitov 2021-07-20   958   * Patched value is 
determined by relocation kind and target specification.
b0588390dbcedc Alexei Starovoitov 2021-07-20   959   * For existence 
relocations target spec will be NULL if field/type is not found.
b0588390dbcedc Alexei Starovoitov 2021-07-20   960   * Expected insn->imm value 
is determined using relocation kind and local
b0588390dbcedc Alexei Starovoitov 2021-07-20   961   * spec, and is checked 
before patching instruction. If actual insn->imm value
b0588390dbcedc Alexei Starovoitov 2021-07-20   962   * is wrong, bail out with 
error.
b0588390dbcedc Alexei Starovoitov 2021-07-20   963   *
b0588390dbcedc Alexei Starovoitov 2021-07-20   964   * Currently supported 
classes of BPF instruction are:
b0588390dbcedc Alexei Starovoitov 2021-07-20   965   * 1. rX = <imm> 
(assignment with immediate operand);
b0588390dbcedc Alexei Starovoitov 2021-07-20   966   * 2. rX += <imm> 
(arithmetic operations with immediate operand);
b0588390dbcedc Alexei Starovoitov 2021-07-20   967   * 3. rX = <imm64> (load 
with 64-bit immediate value);
b0588390dbcedc Alexei Starovoitov 2021-07-20   968   * 4. rX = *(T *)(rY + 
<off>), where T is one of {u8, u16, u32, u64};
b0588390dbcedc Alexei Starovoitov 2021-07-20   969   * 5. *(T *)(rX + <off>) = 
rY, where T is one of {u8, u16, u32, u64};
b0588390dbcedc Alexei Starovoitov 2021-07-20   970   * 6. *(T *)(rX + <off>) = 
<imm>, where T is one of {u8, u16, u32, u64}.
b0588390dbcedc Alexei Starovoitov 2021-07-20   971   */
b0588390dbcedc Alexei Starovoitov 2021-07-20   972  static int 
bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
b0588390dbcedc Alexei Starovoitov 2021-07-20   973                             
int insn_idx, const struct bpf_core_relo *relo,
b0588390dbcedc Alexei Starovoitov 2021-07-20   974                             
int relo_idx, const struct bpf_core_relo_res *res)
b0588390dbcedc Alexei Starovoitov 2021-07-20   975  {
b0588390dbcedc Alexei Starovoitov 2021-07-20   976      __u32 orig_val, new_val;
b0588390dbcedc Alexei Starovoitov 2021-07-20   977      __u8 class;
b0588390dbcedc Alexei Starovoitov 2021-07-20   978  
b0588390dbcedc Alexei Starovoitov 2021-07-20   979      class = 
BPF_CLASS(insn->code);
b0588390dbcedc Alexei Starovoitov 2021-07-20   980  
b0588390dbcedc Alexei Starovoitov 2021-07-20   981      if (res->poison) {
b0588390dbcedc Alexei Starovoitov 2021-07-20   982  poison:
b0588390dbcedc Alexei Starovoitov 2021-07-20   983              /* poison 
second part of ldimm64 to avoid confusing error from
b0588390dbcedc Alexei Starovoitov 2021-07-20   984               * verifier 
about "unknown opcode 00"
b0588390dbcedc Alexei Starovoitov 2021-07-20   985               */
b0588390dbcedc Alexei Starovoitov 2021-07-20   986              if 
(is_ldimm64_insn(insn))
b0588390dbcedc Alexei Starovoitov 2021-07-20   987                      
bpf_core_poison_insn(prog_name, relo_idx, insn_idx + 1, insn + 1);
b0588390dbcedc Alexei Starovoitov 2021-07-20   988              
bpf_core_poison_insn(prog_name, relo_idx, insn_idx, insn);
b0588390dbcedc Alexei Starovoitov 2021-07-20   989              return 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20   990      }
b0588390dbcedc Alexei Starovoitov 2021-07-20   991  
b0588390dbcedc Alexei Starovoitov 2021-07-20   992      orig_val = 
res->orig_val;
b0588390dbcedc Alexei Starovoitov 2021-07-20   993      new_val = res->new_val;
b0588390dbcedc Alexei Starovoitov 2021-07-20   994  
b0588390dbcedc Alexei Starovoitov 2021-07-20   995      switch (class) {
b0588390dbcedc Alexei Starovoitov 2021-07-20   996      case BPF_ALU:
b0588390dbcedc Alexei Starovoitov 2021-07-20   997      case BPF_ALU64:
b0588390dbcedc Alexei Starovoitov 2021-07-20   998              if 
(BPF_SRC(insn->code) != BPF_K)
b0588390dbcedc Alexei Starovoitov 2021-07-20   999                      return 
-EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1000              if 
(res->validate && insn->imm != orig_val) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1001                      
pr_warn("prog '%s': relo #%d: unexpected insn #%d (ALU/ALU64) value: got %u, 
exp %u -> %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1002                              
prog_name, relo_idx,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1003                              
insn_idx, insn->imm, orig_val, new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1004                      return 
-EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1005              }
b0588390dbcedc Alexei Starovoitov 2021-07-20  1006              orig_val = 
insn->imm;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1007              insn->imm = 
new_val;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1008              pr_debug("prog 
'%s': relo #%d: patched insn #%d (ALU/ALU64) imm %u -> %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1009                       
prog_name, relo_idx, insn_idx,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1010                       
orig_val, new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1011              break;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1012      case BPF_LDX:
b0588390dbcedc Alexei Starovoitov 2021-07-20  1013      case BPF_ST:
b0588390dbcedc Alexei Starovoitov 2021-07-20  1014      case BPF_STX:
b0588390dbcedc Alexei Starovoitov 2021-07-20  1015              if 
(res->validate && insn->off != orig_val) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1016                      
pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDX/ST/STX) value: got %u, 
exp %u -> %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1017                              
prog_name, relo_idx, insn_idx, insn->off, orig_val, new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1018                      return 
-EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1019              }
b0588390dbcedc Alexei Starovoitov 2021-07-20  1020              if (new_val > 
SHRT_MAX) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1021                      
pr_warn("prog '%s': relo #%d: insn #%d (LDX/ST/STX) value too big: %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1022                              
prog_name, relo_idx, insn_idx, new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1023                      return 
-ERANGE;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1024              }
b0588390dbcedc Alexei Starovoitov 2021-07-20 @1025              if 
(res->fail_memsz_adjust) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1026                      
pr_warn("prog '%s': relo #%d: insn #%d (LDX/ST/STX) accesses field incorrectly. 
"
b0588390dbcedc Alexei Starovoitov 2021-07-20  1027                              
"Make sure you are accessing pointers, unsigned integers, or fields of matching 
type and size.\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1028                              
prog_name, relo_idx, insn_idx);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1029                      goto 
poison;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1030              }
b0588390dbcedc Alexei Starovoitov 2021-07-20  1031  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1032              orig_val = 
insn->off;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1033              insn->off = 
new_val;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1034              pr_debug("prog 
'%s': relo #%d: patched insn #%d (LDX/ST/STX) off %u -> %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1035                       
prog_name, relo_idx, insn_idx, orig_val, new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1036  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1037              if (res->new_sz 
!= res->orig_sz) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1038                      int 
insn_bytes_sz, insn_bpf_sz;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1039  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1040                      
insn_bytes_sz = insn_bpf_size_to_bytes(insn);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1041                      if 
(insn_bytes_sz != res->orig_sz) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1042                              
pr_warn("prog '%s': relo #%d: insn #%d (LDX/ST/STX) unexpected mem size: got 
%d, exp %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1043                              
        prog_name, relo_idx, insn_idx, insn_bytes_sz, res->orig_sz);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1044                              
return -EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1045                      }
b0588390dbcedc Alexei Starovoitov 2021-07-20  1046  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1047                      
insn_bpf_sz = insn_bytes_to_bpf_size(res->new_sz);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1048                      if 
(insn_bpf_sz < 0) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1049                              
pr_warn("prog '%s': relo #%d: insn #%d (LDX/ST/STX) invalid new mem size: %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1050                              
        prog_name, relo_idx, insn_idx, res->new_sz);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1051                              
return -EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1052                      }
b0588390dbcedc Alexei Starovoitov 2021-07-20  1053  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1054                      
insn->code = BPF_MODE(insn->code) | insn_bpf_sz | BPF_CLASS(insn->code);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1055                      
pr_debug("prog '%s': relo #%d: patched insn #%d (LDX/ST/STX) mem_sz %u -> %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1056                              
 prog_name, relo_idx, insn_idx, res->orig_sz, res->new_sz);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1057              }
b0588390dbcedc Alexei Starovoitov 2021-07-20  1058              break;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1059      case BPF_LD: {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1060              __u64 imm;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1061  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1062              if 
(!is_ldimm64_insn(insn) ||
b0588390dbcedc Alexei Starovoitov 2021-07-20  1063                  
insn[0].src_reg != 0 || insn[0].off != 0 ||
b0588390dbcedc Alexei Starovoitov 2021-07-20  1064                  
insn[1].code != 0 || insn[1].dst_reg != 0 ||
b0588390dbcedc Alexei Starovoitov 2021-07-20  1065                  
insn[1].src_reg != 0 || insn[1].off != 0) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1066                      
pr_warn("prog '%s': relo #%d: insn #%d (LDIMM64) has unexpected form\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1067                              
prog_name, relo_idx, insn_idx);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1068                      return 
-EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1069              }
b0588390dbcedc Alexei Starovoitov 2021-07-20  1070  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1071              imm = 
insn[0].imm + ((__u64)insn[1].imm << 32);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1072              if 
(res->validate && imm != orig_val) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1073                      
pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDIMM64) value: got %llu, 
exp %u -> %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1074                              
prog_name, relo_idx,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1075                              
insn_idx, (unsigned long long)imm,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1076                              
orig_val, new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1077                      return 
-EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1078              }
b0588390dbcedc Alexei Starovoitov 2021-07-20  1079  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1080              insn[0].imm = 
new_val;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1081              insn[1].imm = 
0; /* currently only 32-bit values are supported */
b0588390dbcedc Alexei Starovoitov 2021-07-20  1082              pr_debug("prog 
'%s': relo #%d: patched insn #%d (LDIMM64) imm64 %llu -> %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1083                       
prog_name, relo_idx, insn_idx,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1084                       
(unsigned long long)imm, new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1085              break;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1086      }
b0588390dbcedc Alexei Starovoitov 2021-07-20  1087      default:
b0588390dbcedc Alexei Starovoitov 2021-07-20  1088              pr_warn("prog 
'%s': relo #%d: trying to relocate unrecognized insn #%d, code:0x%x, src:0x%x, 
dst:0x%x, off:0x%x, imm:0x%x\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1089                      
prog_name, relo_idx, insn_idx, insn->code,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1090                      
insn->src_reg, insn->dst_reg, insn->off, insn->imm);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1091              return -EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1092      }
b0588390dbcedc Alexei Starovoitov 2021-07-20  1093  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1094      return 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1095  }
b0588390dbcedc Alexei Starovoitov 2021-07-20  1096  

:::::: The code at line 1025 was first introduced by commit
:::::: b0588390dbcedcd74fab6ffb8afe8d52380fd8b6 libbpf: Split CO-RE logic into 
relo_core.c.

:::::: TO: Alexei Starovoitov <[email protected]>
:::::: CC: Andrii Nakryiko <[email protected]>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

Attachment: .config.gz
Description: application/gzip

_______________________________________________
kbuild mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to