Re: [PATCH bpf-next v3 5/7] bpf: extract map key pointer calculation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/6/25 00:19, Eduard Zingerman wrote:
On Fri, 2025-09-05 at 17:45 +0100, Mykyta Yatsenko wrote:

[...]

+static void *map_key_from_value(struct bpf_map *map, void *value, u32 *arr_idx)
`arr_idx` is unused at every call site of this function.
And even if it was used, why both set through pointer and return same value?
this function returns the pointer to map key; in case of array map, map key is an array index,
which is not stored anywhere in the map explicitly.
arr_idx is a container for the array map key, we need to pass it from the outside so that the
lifetime is long enough.
In case of hash map, we return the pointer to the actual key, stored in the map,
arr_idx is not needed then.

+{
+	if (map->map_type == BPF_MAP_TYPE_ARRAY) {
+		struct bpf_array *array = container_of(map, struct bpf_array, map);
+
+		*arr_idx = ((char *)value - array->value) / array->elem_size;
+		return arr_idx;
+	}
+	BUG_ON(map->map_type != BPF_MAP_TYPE_HASH && map->map_type != BPF_MAP_TYPE_LRU_HASH);
+	return (void *)value - round_up(map->key_size, 8);
+}
+
[...]





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux