Lines Matching +full:step +full:- +full:size

1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
12 #include "bpf-utils.h"
18 int size_offset; /* > 0: offset of rec size,
19 * < 0: fix size of -size_offset
27 -1,
32 -1,
37 -(int)sizeof(__u32),
42 -(int)sizeof(__u64),
47 -(int)sizeof(__u32),
67 -(int)sizeof(__u8) * BPF_TAG_SIZE,
79 return -(int)offset; in bpf_prog_info_read_offset_u32()
89 return -(int)offset; in bpf_prog_info_read_offset_u64()
121 return ERR_PTR(-EINVAL); in get_bpf_prog_info_linear()
123 /* step 1: get array dimensions */ in get_bpf_prog_info_linear()
127 return ERR_PTR(-EFAULT); in get_bpf_prog_info_linear()
130 /* step 2: calculate total size of all arrays */ in get_bpf_prog_info_linear()
134 __u32 count, size; in get_bpf_prog_info_linear() local
139 if (info_len < desc->array_offset + sizeof(__u32) || in get_bpf_prog_info_linear()
140 info_len < desc->count_offset + sizeof(__u32) || in get_bpf_prog_info_linear()
141 (desc->size_offset > 0 && info_len < (__u32)desc->size_offset)) in get_bpf_prog_info_linear()
149 count = bpf_prog_info_read_offset_u32(&info, desc->count_offset); in get_bpf_prog_info_linear()
150 size = bpf_prog_info_read_offset_u32(&info, desc->size_offset); in get_bpf_prog_info_linear()
152 data_len += roundup(count * size, sizeof(__u64)); in get_bpf_prog_info_linear()
155 /* step 3: allocate continuous memory */ in get_bpf_prog_info_linear()
158 return ERR_PTR(-ENOMEM); in get_bpf_prog_info_linear()
160 /* step 4: fill data to info_linear->info */ in get_bpf_prog_info_linear()
161 info_linear->arrays = arrays; in get_bpf_prog_info_linear()
162 memset(&info_linear->info, 0, sizeof(info)); in get_bpf_prog_info_linear()
163 ptr = info_linear->data; in get_bpf_prog_info_linear()
167 __u32 count, size; in get_bpf_prog_info_linear() local
173 count = bpf_prog_info_read_offset_u32(&info, desc->count_offset); in get_bpf_prog_info_linear()
174 size = bpf_prog_info_read_offset_u32(&info, desc->size_offset); in get_bpf_prog_info_linear()
175 bpf_prog_info_set_offset_u32(&info_linear->info, in get_bpf_prog_info_linear()
176 desc->count_offset, count); in get_bpf_prog_info_linear()
177 bpf_prog_info_set_offset_u32(&info_linear->info, in get_bpf_prog_info_linear()
178 desc->size_offset, size); in get_bpf_prog_info_linear()
179 bpf_prog_info_set_offset_u64(&info_linear->info, in get_bpf_prog_info_linear()
180 desc->array_offset, in get_bpf_prog_info_linear()
182 ptr += roundup(count * size, sizeof(__u64)); in get_bpf_prog_info_linear()
185 /* step 5: call syscall again to get required arrays */ in get_bpf_prog_info_linear()
186 err = bpf_obj_get_info_by_fd(fd, &info_linear->info, &info_len); in get_bpf_prog_info_linear()
190 return ERR_PTR(-EFAULT); in get_bpf_prog_info_linear()
193 /* step 6: verify the data */ in get_bpf_prog_info_linear()
202 v1 = bpf_prog_info_read_offset_u32(&info, desc->count_offset); in get_bpf_prog_info_linear()
203 v2 = bpf_prog_info_read_offset_u32(&info_linear->info, in get_bpf_prog_info_linear()
204 desc->count_offset); in get_bpf_prog_info_linear()
208 v1 = bpf_prog_info_read_offset_u32(&info, desc->size_offset); in get_bpf_prog_info_linear()
209 v2 = bpf_prog_info_read_offset_u32(&info_linear->info, in get_bpf_prog_info_linear()
210 desc->size_offset); in get_bpf_prog_info_linear()
212 pr_warning("%s: mismatch in rec size\n", __func__); in get_bpf_prog_info_linear()
215 /* step 7: update info_len and data_len */ in get_bpf_prog_info_linear()
216 info_linear->info_len = sizeof(struct bpf_prog_info); in get_bpf_prog_info_linear()
217 info_linear->data_len = data_len; in get_bpf_prog_info_linear()
230 if ((info_linear->arrays & (1UL << i)) == 0) in bpil_addr_to_offs()
234 addr = bpf_prog_info_read_offset_u64(&info_linear->info, in bpil_addr_to_offs()
235 desc->array_offset); in bpil_addr_to_offs()
236 offs = addr - ptr_to_u64(info_linear->data); in bpil_addr_to_offs()
237 bpf_prog_info_set_offset_u64(&info_linear->info, in bpil_addr_to_offs()
238 desc->array_offset, offs); in bpil_addr_to_offs()
250 if ((info_linear->arrays & (1UL << i)) == 0) in bpil_offs_to_addr()
254 offs = bpf_prog_info_read_offset_u64(&info_linear->info, in bpil_offs_to_addr()
255 desc->array_offset); in bpil_offs_to_addr()
256 addr = offs + ptr_to_u64(info_linear->data); in bpil_offs_to_addr()
257 bpf_prog_info_set_offset_u64(&info_linear->info, in bpil_offs_to_addr()
258 desc->array_offset, addr); in bpil_offs_to_addr()