Skip to content

Commit 032a6b3

Browse files
rdnaborkmann
authored andcommitted
bpf: Rename bpf_htab to bpf_shtab in sock_map
There are two different `struct bpf_htab` in bpf code in the following files: - kernel/bpf/hashtab.c - net/core/sock_map.c It makes it impossible to find proper btf_id by name = "bpf_htab" and kind = BTF_KIND_STRUCT what is needed to support access to map ptr so that bpf program can access `struct bpf_htab` fields. To make it possible one of the struct-s should be renamed, sock_map.c looks like a better candidate for rename since it's specialized version of hashtab. Rename it to bpf_shtab ("sh" stands for Sock Hash). Signed-off-by: Andrey Ignatov <rdna@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: John Fastabend <john.fastabend@gmail.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Link: https://lore.kernel.org/bpf/c006a639e03c64ca50fc87c4bb627e0bfba90f4e.1592600985.git.rdna@fb.com
1 parent a2d0d62 commit 032a6b3

1 file changed

Lines changed: 41 additions & 41 deletions

File tree

‎net/core/sock_map.c‎

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -655,22 +655,22 @@ const struct bpf_map_ops sock_map_ops = {
655655
.map_check_btf = map_check_no_btf,
656656
};
657657

658-
struct bpf_htab_elem {
658+
struct bpf_shtab_elem {
659659
struct rcu_head rcu;
660660
u32 hash;
661661
struct sock *sk;
662662
struct hlist_node node;
663663
u8 key[];
664664
};
665665

666-
struct bpf_htab_bucket {
666+
struct bpf_shtab_bucket {
667667
struct hlist_head head;
668668
raw_spinlock_t lock;
669669
};
670670

671-
struct bpf_htab {
671+
struct bpf_shtab {
672672
struct bpf_map map;
673-
struct bpf_htab_bucket *buckets;
673+
struct bpf_shtab_bucket *buckets;
674674
u32 buckets_num;
675675
u32 elem_size;
676676
struct sk_psock_progs progs;
@@ -682,17 +682,17 @@ static inline u32 sock_hash_bucket_hash(const void *key, u32 len)
682682
return jhash(key, len, 0);
683683
}
684684

685-
static struct bpf_htab_bucket *sock_hash_select_bucket(struct bpf_htab *htab,
686-
u32 hash)
685+
static struct bpf_shtab_bucket *sock_hash_select_bucket(struct bpf_shtab *htab,
686+
u32 hash)
687687
{
688688
return &htab->buckets[hash & (htab->buckets_num - 1)];
689689
}
690690

691-
static struct bpf_htab_elem *
691+
static struct bpf_shtab_elem *
692692
sock_hash_lookup_elem_raw(struct hlist_head *head, u32 hash, void *key,
693693
u32 key_size)
694694
{
695-
struct bpf_htab_elem *elem;
695+
struct bpf_shtab_elem *elem;
696696

697697
hlist_for_each_entry_rcu(elem, head, node) {
698698
if (elem->hash == hash &&
@@ -705,10 +705,10 @@ sock_hash_lookup_elem_raw(struct hlist_head *head, u32 hash, void *key,
705705

706706
static struct sock *__sock_hash_lookup_elem(struct bpf_map *map, void *key)
707707
{
708-
struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
708+
struct bpf_shtab *htab = container_of(map, struct bpf_shtab, map);
709709
u32 key_size = map->key_size, hash;
710-
struct bpf_htab_bucket *bucket;
711-
struct bpf_htab_elem *elem;
710+
struct bpf_shtab_bucket *bucket;
711+
struct bpf_shtab_elem *elem;
712712

713713
WARN_ON_ONCE(!rcu_read_lock_held());
714714

@@ -719,8 +719,8 @@ static struct sock *__sock_hash_lookup_elem(struct bpf_map *map, void *key)
719719
return elem ? elem->sk : NULL;
720720
}
721721

722-
static void sock_hash_free_elem(struct bpf_htab *htab,
723-
struct bpf_htab_elem *elem)
722+
static void sock_hash_free_elem(struct bpf_shtab *htab,
723+
struct bpf_shtab_elem *elem)
724724
{
725725
atomic_dec(&htab->count);
726726
kfree_rcu(elem, rcu);
@@ -729,9 +729,9 @@ static void sock_hash_free_elem(struct bpf_htab *htab,
729729
static void sock_hash_delete_from_link(struct bpf_map *map, struct sock *sk,
730730
void *link_raw)
731731
{
732-
struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
733-
struct bpf_htab_elem *elem_probe, *elem = link_raw;
734-
struct bpf_htab_bucket *bucket;
732+
struct bpf_shtab *htab = container_of(map, struct bpf_shtab, map);
733+
struct bpf_shtab_elem *elem_probe, *elem = link_raw;
734+
struct bpf_shtab_bucket *bucket;
735735

736736
WARN_ON_ONCE(!rcu_read_lock_held());
737737
bucket = sock_hash_select_bucket(htab, elem->hash);
@@ -753,10 +753,10 @@ static void sock_hash_delete_from_link(struct bpf_map *map, struct sock *sk,
753753

754754
static int sock_hash_delete_elem(struct bpf_map *map, void *key)
755755
{
756-
struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
756+
struct bpf_shtab *htab = container_of(map, struct bpf_shtab, map);
757757
u32 hash, key_size = map->key_size;
758-
struct bpf_htab_bucket *bucket;
759-
struct bpf_htab_elem *elem;
758+
struct bpf_shtab_bucket *bucket;
759+
struct bpf_shtab_elem *elem;
760760
int ret = -ENOENT;
761761

762762
hash = sock_hash_bucket_hash(key, key_size);
@@ -774,12 +774,12 @@ static int sock_hash_delete_elem(struct bpf_map *map, void *key)
774774
return ret;
775775
}
776776

777-
static struct bpf_htab_elem *sock_hash_alloc_elem(struct bpf_htab *htab,
778-
void *key, u32 key_size,
779-
u32 hash, struct sock *sk,
780-
struct bpf_htab_elem *old)
777+
static struct bpf_shtab_elem *sock_hash_alloc_elem(struct bpf_shtab *htab,
778+
void *key, u32 key_size,
779+
u32 hash, struct sock *sk,
780+
struct bpf_shtab_elem *old)
781781
{
782-
struct bpf_htab_elem *new;
782+
struct bpf_shtab_elem *new;
783783

784784
if (atomic_inc_return(&htab->count) > htab->map.max_entries) {
785785
if (!old) {
@@ -803,10 +803,10 @@ static struct bpf_htab_elem *sock_hash_alloc_elem(struct bpf_htab *htab,
803803
static int sock_hash_update_common(struct bpf_map *map, void *key,
804804
struct sock *sk, u64 flags)
805805
{
806-
struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
806+
struct bpf_shtab *htab = container_of(map, struct bpf_shtab, map);
807807
u32 key_size = map->key_size, hash;
808-
struct bpf_htab_elem *elem, *elem_new;
809-
struct bpf_htab_bucket *bucket;
808+
struct bpf_shtab_elem *elem, *elem_new;
809+
struct bpf_shtab_bucket *bucket;
810810
struct sk_psock_link *link;
811811
struct sk_psock *psock;
812812
int ret;
@@ -916,8 +916,8 @@ static int sock_hash_update_elem(struct bpf_map *map, void *key,
916916
static int sock_hash_get_next_key(struct bpf_map *map, void *key,
917917
void *key_next)
918918
{
919-
struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
920-
struct bpf_htab_elem *elem, *elem_next;
919+
struct bpf_shtab *htab = container_of(map, struct bpf_shtab, map);
920+
struct bpf_shtab_elem *elem, *elem_next;
921921
u32 hash, key_size = map->key_size;
922922
struct hlist_head *head;
923923
int i = 0;
@@ -931,7 +931,7 @@ static int sock_hash_get_next_key(struct bpf_map *map, void *key,
931931
goto find_first_elem;
932932

933933
elem_next = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(&elem->node)),
934-
struct bpf_htab_elem, node);
934+
struct bpf_shtab_elem, node);
935935
if (elem_next) {
936936
memcpy(key_next, elem_next->key, key_size);
937937
return 0;
@@ -943,7 +943,7 @@ static int sock_hash_get_next_key(struct bpf_map *map, void *key,
943943
for (; i < htab->buckets_num; i++) {
944944
head = &sock_hash_select_bucket(htab, i)->head;
945945
elem_next = hlist_entry_safe(rcu_dereference_raw(hlist_first_rcu(head)),
946-
struct bpf_htab_elem, node);
946+
struct bpf_shtab_elem, node);
947947
if (elem_next) {
948948
memcpy(key_next, elem_next->key, key_size);
949949
return 0;
@@ -955,7 +955,7 @@ static int sock_hash_get_next_key(struct bpf_map *map, void *key,
955955

956956
static struct bpf_map *sock_hash_alloc(union bpf_attr *attr)
957957
{
958-
struct bpf_htab *htab;
958+
struct bpf_shtab *htab;
959959
int i, err;
960960
u64 cost;
961961

@@ -977,15 +977,15 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr)
977977
bpf_map_init_from_attr(&htab->map, attr);
978978

979979
htab->buckets_num = roundup_pow_of_two(htab->map.max_entries);
980-
htab->elem_size = sizeof(struct bpf_htab_elem) +
980+
htab->elem_size = sizeof(struct bpf_shtab_elem) +
981981
round_up(htab->map.key_size, 8);
982982
if (htab->buckets_num == 0 ||
983-
htab->buckets_num > U32_MAX / sizeof(struct bpf_htab_bucket)) {
983+
htab->buckets_num > U32_MAX / sizeof(struct bpf_shtab_bucket)) {
984984
err = -EINVAL;
985985
goto free_htab;
986986
}
987987

988-
cost = (u64) htab->buckets_num * sizeof(struct bpf_htab_bucket) +
988+
cost = (u64) htab->buckets_num * sizeof(struct bpf_shtab_bucket) +
989989
(u64) htab->elem_size * htab->map.max_entries;
990990
if (cost >= U32_MAX - PAGE_SIZE) {
991991
err = -EINVAL;
@@ -996,7 +996,7 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr)
996996
goto free_htab;
997997

998998
htab->buckets = bpf_map_area_alloc(htab->buckets_num *
999-
sizeof(struct bpf_htab_bucket),
999+
sizeof(struct bpf_shtab_bucket),
10001000
htab->map.numa_node);
10011001
if (!htab->buckets) {
10021002
bpf_map_charge_finish(&htab->map.memory);
@@ -1017,10 +1017,10 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr)
10171017

10181018
static void sock_hash_free(struct bpf_map *map)
10191019
{
1020-
struct bpf_htab *htab = container_of(map, struct bpf_htab, map);
1021-
struct bpf_htab_bucket *bucket;
1020+
struct bpf_shtab *htab = container_of(map, struct bpf_shtab, map);
1021+
struct bpf_shtab_bucket *bucket;
10221022
struct hlist_head unlink_list;
1023-
struct bpf_htab_elem *elem;
1023+
struct bpf_shtab_elem *elem;
10241024
struct hlist_node *node;
10251025
int i;
10261026

@@ -1096,7 +1096,7 @@ static void *sock_hash_lookup(struct bpf_map *map, void *key)
10961096

10971097
static void sock_hash_release_progs(struct bpf_map *map)
10981098
{
1099-
psock_progs_drop(&container_of(map, struct bpf_htab, map)->progs);
1099+
psock_progs_drop(&container_of(map, struct bpf_shtab, map)->progs);
11001100
}
11011101

11021102
BPF_CALL_4(bpf_sock_hash_update, struct bpf_sock_ops_kern *, sops,
@@ -1194,7 +1194,7 @@ static struct sk_psock_progs *sock_map_progs(struct bpf_map *map)
11941194
case BPF_MAP_TYPE_SOCKMAP:
11951195
return &container_of(map, struct bpf_stab, map)->progs;
11961196
case BPF_MAP_TYPE_SOCKHASH:
1197-
return &container_of(map, struct bpf_htab, map)->progs;
1197+
return &container_of(map, struct bpf_shtab, map)->progs;
11981198
default:
11991199
break;
12001200
}

0 commit comments

Comments
 (0)