@@ -157,12 +157,12 @@ static void __bpf_local_storage_free(struct bpf_local_storage *local_storage,
157157
158158static void bpf_local_storage_free (struct bpf_local_storage * local_storage ,
159159 struct bpf_local_storage_map * smap ,
160- bool bpf_ma , bool reuse_now )
160+ bool reuse_now )
161161{
162162 if (!local_storage )
163163 return ;
164164
165- if (!bpf_ma ) {
165+ if (!local_storage -> bpf_ma ) {
166166 __bpf_local_storage_free (local_storage , reuse_now );
167167 return ;
168168 }
@@ -336,47 +336,12 @@ static bool bpf_selem_unlink_storage_nolock(struct bpf_local_storage *local_stor
336336 return free_local_storage ;
337337}
338338
339- static bool check_storage_bpf_ma (struct bpf_local_storage * local_storage ,
340- struct bpf_local_storage_map * storage_smap ,
341- struct bpf_local_storage_elem * selem )
342- {
343-
344- struct bpf_local_storage_map * selem_smap ;
345-
346- /* local_storage->smap may be NULL. If it is, get the bpf_ma
347- * from any selem in the local_storage->list. The bpf_ma of all
348- * local_storage and selem should have the same value
349- * for the same map type.
350- *
351- * If the local_storage->list is already empty, the caller will not
352- * care about the bpf_ma value also because the caller is not
353- * responsible to free the local_storage.
354- */
355-
356- if (storage_smap )
357- return storage_smap -> bpf_ma ;
358-
359- if (!selem ) {
360- struct hlist_node * n ;
361-
362- n = rcu_dereference_check (hlist_first_rcu (& local_storage -> list ),
363- bpf_rcu_lock_held ());
364- if (!n )
365- return false;
366-
367- selem = hlist_entry (n , struct bpf_local_storage_elem , snode );
368- }
369- selem_smap = rcu_dereference_check (SDATA (selem )-> smap , bpf_rcu_lock_held ());
370-
371- return selem_smap -> bpf_ma ;
372- }
373-
374339static void bpf_selem_unlink_storage (struct bpf_local_storage_elem * selem ,
375340 bool reuse_now )
376341{
377342 struct bpf_local_storage_map * storage_smap ;
378343 struct bpf_local_storage * local_storage ;
379- bool bpf_ma , free_local_storage = false;
344+ bool free_local_storage = false;
380345 HLIST_HEAD (selem_free_list );
381346 unsigned long flags ;
382347
@@ -388,7 +353,6 @@ static void bpf_selem_unlink_storage(struct bpf_local_storage_elem *selem,
388353 bpf_rcu_lock_held ());
389354 storage_smap = rcu_dereference_check (local_storage -> smap ,
390355 bpf_rcu_lock_held ());
391- bpf_ma = check_storage_bpf_ma (local_storage , storage_smap , selem );
392356
393357 raw_spin_lock_irqsave (& local_storage -> lock , flags );
394358 if (likely (selem_linked_to_storage (selem )))
@@ -399,7 +363,7 @@ static void bpf_selem_unlink_storage(struct bpf_local_storage_elem *selem,
399363 bpf_selem_free_list (& selem_free_list , reuse_now );
400364
401365 if (free_local_storage )
402- bpf_local_storage_free (local_storage , storage_smap , bpf_ma , reuse_now );
366+ bpf_local_storage_free (local_storage , storage_smap , reuse_now );
403367}
404368
405369void bpf_selem_link_storage_nolock (struct bpf_local_storage * local_storage ,
@@ -506,6 +470,7 @@ int bpf_local_storage_alloc(void *owner,
506470 INIT_HLIST_HEAD (& storage -> list );
507471 raw_spin_lock_init (& storage -> lock );
508472 storage -> owner = owner ;
473+ storage -> bpf_ma = smap -> bpf_ma ;
509474
510475 bpf_selem_link_storage_nolock (storage , first_selem );
511476 bpf_selem_link_map (smap , first_selem );
@@ -542,7 +507,7 @@ int bpf_local_storage_alloc(void *owner,
542507 return 0 ;
543508
544509uncharge :
545- bpf_local_storage_free (storage , smap , smap -> bpf_ma , true);
510+ bpf_local_storage_free (storage , smap , true);
546511 mem_uncharge (smap , owner , sizeof (* storage ));
547512 return err ;
548513}
@@ -731,13 +696,12 @@ void bpf_local_storage_destroy(struct bpf_local_storage *local_storage)
731696{
732697 struct bpf_local_storage_map * storage_smap ;
733698 struct bpf_local_storage_elem * selem ;
734- bool bpf_ma , free_storage = false;
699+ bool free_storage = false;
735700 HLIST_HEAD (free_selem_list );
736701 struct hlist_node * n ;
737702 unsigned long flags ;
738703
739704 storage_smap = rcu_dereference_check (local_storage -> smap , bpf_rcu_lock_held ());
740- bpf_ma = check_storage_bpf_ma (local_storage , storage_smap , NULL );
741705
742706 /* Neither the bpf_prog nor the bpf_map's syscall
743707 * could be modifying the local_storage->list now.
@@ -768,7 +732,7 @@ void bpf_local_storage_destroy(struct bpf_local_storage *local_storage)
768732 bpf_selem_free_list (& free_selem_list , true);
769733
770734 if (free_storage )
771- bpf_local_storage_free (local_storage , storage_smap , bpf_ma , true);
735+ bpf_local_storage_free (local_storage , storage_smap , true);
772736}
773737
774738u64 bpf_local_storage_map_mem_usage (const struct bpf_map * map )
0 commit comments