@@ -24,9 +24,10 @@ const struct bpf_prog_ops bpf_extension_prog_ops = {
2424#define TRAMPOLINE_HASH_BITS 10
2525#define TRAMPOLINE_TABLE_SIZE (1 << TRAMPOLINE_HASH_BITS)
2626
27- static struct hlist_head trampoline_table [TRAMPOLINE_TABLE_SIZE ];
27+ static struct hlist_head trampoline_key_table [TRAMPOLINE_TABLE_SIZE ];
28+ static struct hlist_head trampoline_ip_table [TRAMPOLINE_TABLE_SIZE ];
2829
29- /* serializes access to trampoline_table */
30+ /* serializes access to trampoline tables */
3031static DEFINE_MUTEX (trampoline_mutex );
3132
3233#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
@@ -135,15 +136,15 @@ void bpf_image_ksym_del(struct bpf_ksym *ksym)
135136 PAGE_SIZE , true, ksym -> name );
136137}
137138
138- static struct bpf_trampoline * bpf_trampoline_lookup (u64 key )
139+ static struct bpf_trampoline * bpf_trampoline_lookup (u64 key , unsigned long ip )
139140{
140141 struct bpf_trampoline * tr ;
141142 struct hlist_head * head ;
142143 int i ;
143144
144145 mutex_lock (& trampoline_mutex );
145- head = & trampoline_table [hash_64 (key , TRAMPOLINE_HASH_BITS )];
146- hlist_for_each_entry (tr , head , hlist ) {
146+ head = & trampoline_key_table [hash_64 (key , TRAMPOLINE_HASH_BITS )];
147+ hlist_for_each_entry (tr , head , hlist_key ) {
147148 if (tr -> key == key ) {
148149 refcount_inc (& tr -> refcnt );
149150 goto out ;
@@ -164,8 +165,12 @@ static struct bpf_trampoline *bpf_trampoline_lookup(u64 key)
164165#endif
165166
166167 tr -> key = key ;
167- INIT_HLIST_NODE (& tr -> hlist );
168- hlist_add_head (& tr -> hlist , head );
168+ tr -> ip = ftrace_location (ip );
169+ INIT_HLIST_NODE (& tr -> hlist_key );
170+ INIT_HLIST_NODE (& tr -> hlist_ip );
171+ hlist_add_head (& tr -> hlist_key , head );
172+ head = & trampoline_ip_table [hash_64 (tr -> ip , TRAMPOLINE_HASH_BITS )];
173+ hlist_add_head (& tr -> hlist_ip , head );
169174 refcount_set (& tr -> refcnt , 1 );
170175 mutex_init (& tr -> mutex );
171176 for (i = 0 ; i < BPF_TRAMP_MAX ; i ++ )
@@ -801,7 +806,7 @@ void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog)
801806 prog -> aux -> attach_btf_id );
802807
803808 bpf_lsm_find_cgroup_shim (prog , & bpf_func );
804- tr = bpf_trampoline_lookup (key );
809+ tr = bpf_trampoline_lookup (key , 0 );
805810 if (WARN_ON_ONCE (!tr ))
806811 return ;
807812
@@ -821,7 +826,7 @@ struct bpf_trampoline *bpf_trampoline_get(u64 key,
821826{
822827 struct bpf_trampoline * tr ;
823828
824- tr = bpf_trampoline_lookup (key );
829+ tr = bpf_trampoline_lookup (key , tgt_info -> tgt_addr );
825830 if (!tr )
826831 return NULL ;
827832
@@ -857,7 +862,8 @@ void bpf_trampoline_put(struct bpf_trampoline *tr)
857862 * fexit progs. The fentry-only trampoline will be freed via
858863 * multiple rcu callbacks.
859864 */
860- hlist_del (& tr -> hlist );
865+ hlist_del (& tr -> hlist_key );
866+ hlist_del (& tr -> hlist_ip );
861867 if (tr -> fops ) {
862868 ftrace_free_filter (tr -> fops );
863869 kfree (tr -> fops );
@@ -1130,7 +1136,9 @@ static int __init init_trampolines(void)
11301136 int i ;
11311137
11321138 for (i = 0 ; i < TRAMPOLINE_TABLE_SIZE ; i ++ )
1133- INIT_HLIST_HEAD (& trampoline_table [i ]);
1139+ INIT_HLIST_HEAD (& trampoline_key_table [i ]);
1140+ for (i = 0 ; i < TRAMPOLINE_TABLE_SIZE ; i ++ )
1141+ INIT_HLIST_HEAD (& trampoline_ip_table [i ]);
11341142 return 0 ;
11351143}
11361144late_initcall (init_trampolines );
0 commit comments